指定EXCEL文件的各种格式

返回

# excel_format.pl # use strict; use Win32::OLE qw(in with); use Win32::OLE::Const 'Microsoft Excel'; use Win32::OLE::Variant; use utf8; # set perl's OLE module to return Unicode Win32::OLE->Option(CP => Win32::OLE::CP_UTF8, Warn=>3); use Encode; my(%t); # use existing instance if Excel is already running eval {$t{ex} = Win32::OLE->GetActiveObject('Excel.Application')}; die "Excel not installed" if $@; unless (defined $t{ex}) { $t{ex} = Win32::OLE->new('Excel.Application', sub {$_[0]->Quit;}) or die "Oops, cannot start Excel"; } #$t{ex}->{Visible} = 1; # 显示EXCEL $t{ex}->{DisplayAlerts} = 'False'; # get a new workbook $t{book} = $t{ex}->Workbooks->Add; # write to a particular cell $t{sheet} = $t{book}->Worksheets(1); $t{sheet}->Cells(2,2)->{Font}->{Name} = "MS 明朝"; $t{sheet}->Cells(2,2)->{Value} = "日本富士山"; $t{sheet}->Cells(3,2)->{Font}->{Size} = "9"; $t{sheet}->Cells(3,2)->{Font}->{Bold} = "False"; #$t{sheet}->Cells(3,2)->{WrapText} = "True"; $t{sheet}->Cells(3,2)->{Value} = "1983"; with ($t{sheet}->Range("B3"), HorizontalAlignment => xlLeft ); # save and exit $t{excel} = "試験データ.xls"; $t{excel} = encode("utf8",$t{excel}); $t{excel} = decode("utf8",$t{excel}); $t{book}->SaveAs($t{excel}); undef $t{book}; undef $t{ex};
返回