perl 处理excel 实例
发布时间:2020-12-15 21:07:41 所属栏目:大数据 来源:网络整理
导读:1. 实例说明 ?excel 模板先编写宏:NSN_HSPDA ?关闭全部的excel文件,否则会出现无法完全关闭的问题 ?写excel文件,运行宏。 图表最好用公式先生成。 ? 2. 代码? ? ? use Win32::OLE qw(in with);use Win32::OLE::Const 'Microsoft Excel';?$Win32::OLE::War
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 alerts my $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); } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |