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);}总结
以上是内存溢出为你收集整理的perl 处理excel 实例全部内容,希望文章能够帮你解决perl 处理excel 实例所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)