#!/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(); }