I have the following output which I want to convert intoexcel...Any
pointers how to achieve it via Spreadsheet::WriteExcel;
I am a beginer so pardon my lack of knowledge in perl.
lpar_name minmem desmem maxmem minpr despr maxpr
commuq21 2048 8192 12288 0.1 1.0 2.0
commuq20 2048 8192 12288 0.1 1.0 2.0
commuq23 2048 16384 40960 0.1 2.0 4.0
commud18 3072 40960 61440 0.2 2.0 5.0
commup03 2048 24576 30720 0.1 3.0 4.0
commup02 10240 32768 32768 1.0 4.0 8.0
commup01 10240 32768 32768 1.0 4.0 8.0
Regards
Sana
I use Win32::OLE - try sth like this (edited version of my
own code may not work out of the box - for better examples
check Win32::OLE docs)
------------------------------------------
#for OLE automation
use Win32::OLE;
use Win32::OLE::Const "Microsoft Excel";
use Win32::OLE 'in';
use Win32::OLE::Variant;
#get current directory
use Cwd;
use strict;
my $excel;
#--------------------------------------------------------------------------------------
#writes array of array references as new excel spreadsheet
sub write_array_as_excel_file
{
#-------------------------------------------------------------------
#1st is name of output file
my $output_file = shift;
#2nd argument is assumes as refrence to array of array references
#each array references contains values for the whole row in
spreadsheet
my $array_ref = shift;
#-------------------------------------------------------------------
my $dir = cwd();
my $fullname_output_file = $dir.'/'.$output_file;
# use existing instance if Excel is already running
eval
{
$excel = Win32::OLE->GetActiveObject('Excel.Application')
};
die "Excel not installed" if $@;
unless (defined $excel)
{
$excel = Win32::OLE->new('Excel.Application', 'Quit')
or die "Oops, cannot start Excel";
}
#to avoid excessive dialogs when saving in non-Excel format
$excel->{DisplayAlerts} = 0;
# get a new workbook
my $wbook = $excel->Workbooks->Add
|| print STDERR "didnt add new workbook: $!\n";
# write to a particular cell
my $wsheet = $wbook->Worksheets(1);
my $ref;
my $cell_value;
my $row_num = scalar @{$array_ref};
my $col_num = scalar @{$array_ref->[0]};
$wsheet->Range($wsheet->Cells(1,1), $wsheet->Cells($row_num,
$col_num) )->{Value} = $array_ref;
$wbook->SaveAs($fullname_output_file);
$wbook->Close();
}