How to get cell content in to one scalar variable

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Bsr
    New Member
    • Mar 2007
    • 20

    How to get cell content in to one scalar variable

    Hi,
    I have test2.xls file it has some data.

    I want to open that file,read the data from the same file, get the content of the cell in to in scalar variable and display the same(content) at the command prompt.


    Please help me with sample code if anybody knows.its argent for me.


    Regards
    Bhuvan
  • savanm
    New Member
    • Oct 2006
    • 85

    #2
    Hi bhuvan

    Try the following code:

    use strict;
    use Win32::OLE qw(in with);
    use Win32::OLE::Con st 'Microsoft Excel';
    $Win32::OLE::Wa rn = 3; # die on errors...
    my $Excel = Win32::OLE->GetActiveObjec t('Excel.Applic ation')|| Win32::OLE->new('Excel.App lication', 'Quit'); # get already active Excel
    # application or open new
    my $Book = $Excel->Workbooks->Open("C:\\Nava s\\test.xls"); # open Excel file
    my $Sheet = $Book->Worksheets(1 ); # select worksheet number 1
    my $array = $Sheet->Range("A1:D1 ")->{'Value'}; # get the contents
    $Book->Close;
    foreach my $ref_array (@$array) { # loop through the array
    # referenced by $array
    foreach my $scalar (@$ref_array) {
    print "$scalar\t" ;
    }
    print "\n";
    }

    Thanks

    Comment

    Working...