james.f.williamson has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl -w use strict; use Win32::OLE qw(in with); use Win32::OLE::Const 'Microsoft Excel'; $Win32::OLE::Warn = 3; # die on errors... # get already active Excel application or open new my $Excel = Win32::OLE->GetActiveObject('Excel.Application') || Win32::OLE->new('Excel.Application', 'Quit'); my $excel_file = 'C:/work/james_test.xls'; # -e checks to see if the file exists if (-e "$excel_file") { # open Excel file my $Book = $Excel->Workbooks->Open("$excel_file"); } else{ $Excel->{Visible} = 0; $Excel->{DisplayAlerts}=0; #0 is hide alerts $Excel->{SheetsInNewWorkBook} = 1; my $Workbook = $Excel->Workbooks->Add(); my $sheet1 = $Workbook->Worksheets(1); $sheet1->{Name} = "WorkSheet1"; my $sheet2 = $Workbook->Worksheets->Add(); $sheet2->{Name} = "WorkSheet 2"; my @average_values_table = ( [ "1", "2", "3", "4" ], [ "5", "8", "7", "8"], [ "1", "2", "3", "4" ], [ "5", "8", "7", "8"], ); $sheet1 -> Range("A1:D4") -> {Value} = @average_values_table; $Workbook->SaveAs($excel_file); $Workbook->Close(); $Excel->Quit(); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: inserting a perl array into an Excel doc with OLE
by Andrew Coolman (Hermit) on Oct 10, 2008 at 17:37 UTC | |
by Anonymous Monk on Oct 11, 2008 at 08:23 UTC | |
by drodinthe559 (Monk) on Aug 03, 2009 at 21:52 UTC | |
by HelenCr (Monk) on Jan 13, 2013 at 14:28 UTC |