#!/usr/bin/perl use Win32::OLE; use Win32::OLE qw(in with); use Win32::OLE::Variant; use Win32::OLE::Const 'Microsoft Excel'; $Excel = Win32::OLE->GetActiveObject('Excel.Application') || Win32::OLE->new('Excel.Application'); $Excel->{'Visible'} = 0; #0 is hidden, 1 is visible $Excel->{DisplayAlerts}=0; #0 is hide alerts # Open File and Worksheet my $Book = $Excel->Workbooks->Open ('C:\shareP\sp.xlsx'); # open Excel file $Sheet = $Book->Worksheets(1); # Refresh Data (ActiveWorkbook.RefreshAll) $Book->RefreshAll(); # Find Last Column and Row my $LastRow = $Sheet->UsedRange->Find({What=>"*", SearchDirection=>xlPrevious, SearchOrder=>xlByRows})->{Row}; my $LastCol = $Sheet->UsedRange->Find({What=>"*", SearchDirection=>xlPrevious, SearchOrder=>xlByColumns})->{Column}; # read values from each column my @hasher; my $c = "a"; for (my $cn=1; $cn <= $LastCol; $cn++){ for (my $r=2; $r <= $LastRow; $r++){ $hasher[$r-2]{ $Sheet->Range($c.'1')->{Value} } = $Sheet->Range($c.$r)->{Value}; } $c++; } # Save as Excel $Book->Save(); $Book->Close(); $Excel->Quit();