use strict "vars"; use Win32; use Win32::OLE; use Win32::OLE::Const 'Microsoft Excel'; sub excel_open_array($$$$$$) { my ($hist_full, $ref_returned_wkbk, $ref_cell_array, $ref_open_res, $w +ksh_no, $excel_data_range) = @_; my ($excel, $worksheet, $excel_res, $ew_message, $workbook_res); eval { $excel = Win32::OLE->GetActiveObject( 'Excel.Application' ) + }; if( $@ ) { print "[excel_open_array] Excel Installation Failure"; $$ref_open_res = 0; return(); } else { $excel = Win32::OLE->new('Excel.Application', 'Quit') or ($exc +el_res = 0, $ew_message = "Could not create excel object"); $$ref_returned_wkbk = $excel->Workbooks->Open($hist_full) or +($workbook_res = 0, $ew_message = "Could not open excel workbook for +<$hist_full>"); print "[excel_open_array] workbook <$$ref_returned_wkbk> excel + <$excel> res <$workbook_res>\n"; $worksheet = $$ref_returned_wkbk->Worksheets($wksh_no); $$ref_cell_array = $worksheet->range($excel_data_range)->{'val +ue'}; $$ref_open_res = 1; } } sub open_close ($) { my ($hist_full) = @_; my ($returned_wkbk, $cell_array, $open_res, $close_res, $wksh_no, $exc +el_data_range); my ($en_num, $en_mes, $var00, $var01); $wksh_no = 1; $excel_data_range = "A1:Z100"; excel_open_array($hist_full, \$returned_wkbk, \$cell_array, \$open_res +, $wksh_no, $excel_data_range); # check on the open result print "[open_close] open_res <$open_res>\n"; # read the first two cells $var00 = $cell_array->[0][0]; $var01 = $cell_array->[0][1]; print "[open_close] var 00 <$var00> 01 <$var01>\n"; # close workbook $close_res = $returned_wkbk->close(); $en_num = Win32::GetLastError(); $en_mes = Win32::FormatMessage($en_num); print "[open_close] close_res <$close_res> for <$returned_wkbk> error +number <$en_num> message <$en_mes>\n"; } #main my $hist_full = "C:\\test-spreadsheet.xls"; open_close ($hist_full);
In reply to Closing Spreasheet problems by merrymonk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |