Perl Win32::OLE csv2excel

戻る

# csv2excel.pl 07.11.28 # 複數(shù)CSVファイルを1つのexcelファイルに縮約 use strict; use Win32::OLE; use Win32::OLE::Const 'Microsoft Excel'; my(%t,$array); # 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"; } # 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)->{Value} = "foo"; # write a 2 rows by 3 columns range $t{sheet}->Range("A8:C9")->{Value} = [[ undef, 'Xyzzy', 'Plugh' ], [ 82, 'Perl', 3.1415 ]]; # 線を引く $t{sheet}->Range("B5:D5")->Borders(xlEdgeBottom)->{LineStyle} = xlDouble; # print "XyzzyPerl" $array = $t{sheet}->Range("A7:C9")->{Value}; for (@$array) { for (@$_) { print defined($_) ? "$_|" : "<undef>|"; } print "\n"; } $t{book}->Sheets->Add("C:\\test\\g.csv"); # ==>成功していない! # save and exit $t{book}->SaveAs("C:\\test\\test.xls"); undef $t{book}; undef $t{ex};
戻る
寿光市| 仪陇县| 长葛市| 徐闻县| 沾益县| 成武县| 泽普县| 龙里县| 台东市| 阿荣旗| 方山县| 抚远县| 元谋县| 南宫市| 宜兰县| 麻阳| 澄江县| 南乐县| 射阳县| 客服| 会东县| 含山县| 台中市| 沾化县| 普洱| 胶州市| 峨边| 周口市| 玛纳斯县| 金乡县| 兰州市| 仪征市| 常德市| 牟定县| 罗甸县| 山丹县| 锡林浩特市| 通海县| 黑水县| 汕头市| 如东县|