perl 处理excel 实例

来源:互联网 发布:指南针带经纬度软件 编辑:程序博客网 时间:2024/06/05 18:31

1. 实例说明

 excel 模板先编写宏:NSN_HSPDA

 关闭全部的excel文件,否则会出现无法完全关闭的问题

 写excel文件,运行宏。 图表最好用公式先生成。

 

2. 代码 

 

 
use Win32::OLE qw(in with);use Win32::OLE::Const 'Microsoft Excel'; $Win32::OLE::Warn = 3;
sub Save2Excel(){my $KillExcel = `taskkill   /F /IM EXCEL.EXE 2>>nul`;chomp $KillExcel;print "结束Excel程序:$KillExcel \n" if ($KillExcel);my ($csvfilepath,$causevalues,$PSFilterThreshold) = @_;unless  (-e $ExcelReportFilePathName){die "$ExcelReportFilePathName 不存在!\n"}unless  (-e $csvfilepath){die "$csvfilepath 不存在!\n"}my $excel = Win32::OLE->GetActiveObject('Excel.Application') ||               Win32::OLE->new('Excel.Application', 'Quit');$excel->{'Visible'} = 1;        #0 is hidden, 1 is visible$excel->{"DisplayAlerts"}=1;    #0 is hide alertsmy $book  = $excel->Workbooks->Open($ExcelReportFilePathName);my $RowID = 20;my $ColID = 3;my $coversheet = $book->Worksheets(1);foreach my $CauseRatio  (@{$causevalues}){$coversheet->Cells($RowID, $ColID)->{'Value'} = $CauseRatio;$RowID++; } $coversheet->Cells(31, 3)->{'Value'} = $PSFilterThreshold;$coversheet->Cells(71, 2)->{'Value'} = $AlarmCellResValue{"HISTORYALARMBTSNUM"};$coversheet->Cells(71, 3)->{'Value'} = $AlarmCellResValue{"KPIBTSNUM"};$coversheet->Cells(75, 3)->{'Value'} = $AlarmCellResValue{"UNAVAILABILITY"};$coversheet->Cells(76, 3)->{'Value'} = $AlarmCellResValue{"CELLAVAILABLE_0_50"};$coversheet->Cells(77, 3)->{'Value'} = $AlarmCellResValue{"CELLAVAILABLE_50_100"}; $excel->Run("NSN_HSPDA"); $book->Save;#$book->Close;#$book->Quit(); #$excel->Quit();$KillExcel = `taskkill  /F /IM EXCEL.EXE 2>>nul`;chomp $KillExcel;#print "结束Excel程序:$KillExcel \n" if ($KillExcel);}


 

原创粉丝点击