CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Win32 Programming Help:
how to append excel sheet?

 



poolboi
New User

Jan 27, 2008, 6:50 PM

Post #1 of 1 (2931 views)
how to append excel sheet? Can't Post

hi all,

i've got the follow code that output data to an excel

however, i need to append my excel sheet

stuck at this for a week..help will be appreciated..Smile



use Win32::OLE;

# use existing instance if Excel is already running
eval {$ex = Win32::OLE->GetActiveObject('Excel.Application')};
die "Excel not installed" if $@;
unless (defined $ex) {
$ex = Win32::OLE->new('Excel.Application', sub {$_[0]->Quit;})
or die "Oops, cannot start Excel";
}


# get a new workbook
$book = $ex->Workbooks->Add;
$sheet = $book->Worksheets(1);

# write a 2 rows by 3 columns range
$sheet->Range("A1:J2")->{Value} = [['Date','Total (IN)','Succ (IN)','Pk (IN)/Hrs','Pk (OUT)/Hrs','Peak Hour','Total (OUT)','Succ (OUT)','MO(IN)','MO(OUT)'],
[$date, $total_in, $succ_in,$pk_in,$pk_out,"$pk_hour - $pk_hour_dur hr",$total_out,$succ_out ]];

$sheet->Range("K1:L2")->{Value} = [['Pk Msg/sec','Max Pk Msg/sec'],
[$max_pk_msg,$pk_msg]];


foreach(@parameters)
{
$sheet->Cells(2,9)->{Value} = [$parameter_in_array{$_}];
$sheet->Cells(2,10)->{Value} = [$parameter_out_array{$_}];
}

# print "XyzzyPerl"
$array = $sheet->Range("A2:I1")->{Value};
for (@$array) {
for (@$_) {
print defined($_) ? "$_|" : "<undef>|";
}
print "\n";
}

# save and exit

$book->SaveAs ("C:\\Documents and Settings\\clong\\Desktop\\perl\\$save_file_name.xls") ;
undef $book;
undef $ex;



(This post was edited by poolboi on Jan 27, 2008, 6:52 PM)

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives