赞
踩
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);
}

Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。