use strict;
use Spreadsheet::ParseExcel;
use Spreadsheet::ParseExcel::FmtUnicode; #字符编码
my $parser = Spreadsheet::ParseExcel->new();
my $formatter = Spreadsheet::ParseExcel::FmtUnicode->new(Unicode_Map=>"CP936");#设置字符编码
#my $workbook = $parser->parse('Book.xls');
my $workbook = $parser->parse('E:\webdev\project\perl\a.xls', $formatter);#按所设置的字符编码解析
my $log = "demo.log";
if ( !defined $workbook ) {
die $parser->error(), ".\n";
}
open(FILE,">$log");
for my $worksheet ( $workbook->worksheets() ) {
my ( $row_min, $row_max ) = $worksheet->row_range();
my ( $col_min, $col_max ) = $worksheet->col_range();
for my $row ( $row_min .. $row_max ) {
for my $col ( $col_min .. $col_max ) {
my $cell = $worksheet->get_cell( $row, $col );
next unless $cell;
print $cell->value()," ";
print(FILE $cell->value()."\t");
}
print "\n";
print(FILE "\n");
}
}
close(FILE);
View Code 记录下,明天去公司试试效果
use strict;
use warnings;
use Spreadsheet::XLSX;
use Encode;
use Getopt::std;
use File::Basename;
use LWP::Simple;
use URI::Escape;
#my $converter = Text::Iconv -> new ("utf-8", "windows-1251");
#my $excel = Spreadsheet::XLSX -> new ('test.xlsx', $converter);
eval {
my $l = "D:\\log.log";
#读取excel文件
my $excel_path = $ARGV[0];
my $dir = dirname($excel_path);
#设置log文件路径
my $log = $dir."/".$ARGV[1].".log";
open(FILE,">$l");
print(FILE "http://localhost/kwm/source/index.php?s=Admin/Index/extract/log/".$ARGV[1]);
close(FILE);
#print 'http://localhost/kwm/source/index.php?s=Admin/Index/extract/log/'.$ARGV[1];