2013-11-27 34 views
0

我想使用win32 :: OLE模塊編寫現有的XLSX文件。我想按單元格插入值單元格。我也想格式化單元格(字體,顏色,對齊方式等)。我的要求是隻使用Win32的:: OLE模塊,可以請你建議我我必須使用哪種方法,在此先感謝....如何在Perl語言中使用Win32 :: OLE模塊在XLSX文件中的單元格中格式化文本

**formatstring.pl** 

use strict; 
use warnings; 
use win32::OLE; 
our $Excel1 = Win32::OLE->new('Excel.Application'); 
our $Workbook1= $Excel1->Workbooks->Open($outputfilepath); 
my $sheet1 = $Workbook1->Worksheets(1); 
our $RowCount=$sheet1->Usedrange->Rows->{Count}; 
my $g_DS_TestCaseID="sd123"; 
print "RowCount of outputfile: $RowCount"; 
$sheet1->Cells($RowCount+1,1)->{value}=$g_DS_TestCaseID;#here i want to format the text as bold with colorindex as green 

回答

0

我一個很久很久以前做過這樣的事情。這不是一個真正的答案,而是一個指針:

嘗試在Excel中錄製宏時進行此操作。大多數時候,方法和值都可以在不改變COM接口的情況下使用。錄製的宏至少爲您提供了查看方向的指針,通常它會提供您需要使用的確切方法/變量。

0

很簡單:

use FindBin qw($Bin); 
use Win32::OLE; 
use Win32::OLE::Const 'Microsoft Excel'; 
our $Excel = Win32::OLE->new('Excel.Application'); 

$Excel->{'Visible'} = 1; 
$Excel->{DisplayAlerts} = 0; 
our $Workbook = $Excel->Workbooks->Open("$Bin/Test.xls"); 
my $Sheet = $Workbook->Worksheets(1); 


$Sheet->Range("A2")->{Font}->{Bold} = 1; 
$Sheet->Range("A2")->{Interior}->{ColorIndex} = 36; 
相關問題