Hi Monks,
I wrote a script using Win32::OLE module to parse an excel file. I am able to extract the value of the particular cell using the function "$Sheet->Cells($row,$col)->{'Value'}". But I am not able to extract one full row value at one shot.
Example
Input File : test.xls EmpName EmpNumber EmpLocation Shittal 90786 NY Xiang 20874 NJ Here I want to extract the complete row 1 value to one variable. Is it possible? please advise. Expected output: Row two val = > Xiang 20874 NJ
My code is here,
use strict; use Win32::OLE qw(in with); use Win32::OLE::Const 'Microsoft Excel'; # get already active Excel application or open new my $Excel = Win32::OLE->GetActiveObject('Excel.Application') || Win32::OLE->new('Excel.Application', 'Quit'); # open Excel file my $Book = $Excel->Workbooks->Open("D:/test.xls"); my $Sheet = $Book->Worksheets(2); my $Tot_Rows= $Sheet->UsedRange->Rows->{'Count'}; my $Tot_Cols= $Sheet->UsedRange->Columns->{'Count'}; print"Number of Rows=> $Tot_Rows\n"; print"Number of Cols=> $Tot_Cols\n"; foreach my $row (1..10) { foreach my $col (1..10) { # skip empty cells next unless defined $Sheet->Cells($row,$col)->{'Value'}; # print out the contents of a cell printf "At ($row, $col) the value is %s and the formula is %s\n", $Sheet->Cells($row,$col)->{'Value'}, $Sheet->Cells($row,$col)->{'Formula'}; my $newval = $Sheet->Cells($row,$col)->{'Value'}; ; print"Row two val = $sheet->{'value'}; } } # clean up after ourselves $Book->Close;
Thanks,
madtoperl

In reply to How to print row of excel file in perl by madtoperl

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.