Hi All,

I am writing into excel using cgi/perl. When I write a number into a cell it is right aligned, though I want the left alignment. The choices I have are either format the cell left aligned or the whole worksheet formatting to text. Either of them is ok with me. How do I do this through perl? I am using Win32::OLE. Please find the code below. In summary, I'm opening a worksheet and then writing into the cells. Afterwards I am saving as CSV (Comma Separated) and closing the excel sheet. When I write into a cell, even if the value entered is number (i.e., 555) I want it to be left aligned instead of right aligned (which is the default for numbers) If I do the following, this is giving error. Think I am missing something :(
       my    $format = $book->addformat(); # Add a format
       $format->set_align('right');
Below code is ok. I need to integrate the above one.
my $book = $Excel->Workbooks->Add; my $sheet = $book->Worksheets(1); $sheet->Cells(1,1)->{Value} = $name; $sheet->Cells(1,2)->{Value} = $address; $sheet->Cells(1,3)->{Value} = $job; $book->SaveAs( {FileName => "file1.csv", FileFormat =>6 , CreateBackup + => 0} ); $book->Close( {SaveChanges => 0} );
Thanks in advance, Raj.

In reply to Formatting Excel cell using Perl by arajani

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.