為什麼不自動的去把資料庫吐出來的XLS檔案轉成CSV呢?
#!/usr/bin/perl -w use strict; use Spreadsheet::ParseExcel; use utf8; use Encode; # Check for valid number of arguments if ((@ARGV <= 0) || (@ARGV >= 3)) { die("Usage: xls2csv.pl excelFile.xls execFile.csv\n"); } my $file=$ARGV[0]; if($file !~ /\.xls$/){ die "Please input a .xls file\n"; } my ($fHeader,$fTail)=split /\./,((@ARGV>=2)?$ARGV[1]:$file); open FILE,">"."$fHeader".".csv" || die "Can't open file for write!\n"; my $excel = Spreadsheet::ParseExcel::Workbook->Parse($file); foreach my $sheet (@{$excel->{Worksheet}}) { printf("Sheet: %s\n", $sheet->{Name}); $sheet->{MaxRow} ||= $sheet->{MinRow}; foreach my $row ($sheet->{MinRow} .. $sheet->{MaxRow}) { $sheet->{MaxCol} ||= $sheet->{MinCol}; foreach my $col ($sheet->{MinCol} .. $sheet->{MaxCol}) { my $cell = $sheet->{Cells}[$row][$col]; if ($cell) { printf FILE "\"%s\",",encode('utf8',$cell->value()); } } print FILE "\n"; } } close FILE;
沒有留言:
張貼留言