更多內容,請訪問個人 我的博客。字體
若是想實現跨平臺處理excel請移步 perl處理Excel(跨平臺)ui
use FindBin qw($Bin);
use Win32::OLE qw(in with);
use Win32::OLE::Const 'Microsoft Excel';
my $Excel = Win32::OLE->GetActiveObject('Excel.Application') || Win32::OLE->new('Excel.Application', 'Quit');
#不顯示警告窗口
$Excel->{DisplayAlerts} = 0;
my $Book = $Excel->Workbooks->Open($file);
my $Sheet = $Book->Worksheets(1);
#my $Sheet = $Book->Worksheets($sheetName);
#my $SheetName = $Book->Worksheets(1)->{Name};
my $maxRow = $Sheet->UsedRange->Rows->Count;
my $maxCol = $Sheet->UsedRange->Columns->Count;
foreach my $row(1..$maxRow){
foreach my $col(1..$maxCol){
#隱藏的單元格,過濾
next if $Sheet->Range("$row:$row")->EntireRow->{Hidden};
#獲取單元格的值
my $value = $Sheet->Cells($row,$col)->{Value};
#修改單元格填充色
$Sheet->Cells($row,$col)->Interior->{Color} = $InColor;
#字體加粗
$sheet -> Range("G7:H7") -> Font -> {Bold} = "True";
#字體斜體
$sheet -> Range("G7:H7") -> Font -> {Italic} = "True";
#字體下劃線
$sheet -> Range("G7:H7") -> Font -> {Underline} = xlUnderlineStyleSingle;
#字體大小
$sheet -> Range("G7:H7") -> Font -> {Size} = 8;
#字體名稱
$sheet -> Range("G7:H7") -> Font -> {Name} = "Arial";
#字體顏色
$sheet -> Range("G7:H7") -> Font -> {ColorIndex} = 4;
#列寬
$sheet -> Range('A:A') -> {ColumnWidth} = 9.14;
#行高
$sheet -> Range("8:8") -> {RowHeight} = 30;
}
}
$Book->Save();
$Book->Close();
$Excel->Quit();
複製代碼