perl 处理excel 实例

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


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值