【问题标题】:parsing .xls-files with indentations解析带有缩进的 .xls 文件
【发布时间】:2013-10-09 20:28:01
【问题描述】:
我有 5 级缩进的 excel 文件,所以我想我需要 Spreadsheet::ParseExcel::Format
但是当我尝试$format->{Indent}(就像在概要中一样)时,perl 说:
Global symbol "$format" requires explicit package name
我尝试了不同的方法,还尝试了Spreadsheet::ParseExcel::Format->new() 和其他方法,但仍然没有成功。
什么是正确的概要,或者是否有其他方法可以解析 xls 文件中的缩进?
也许一些二进制? (xlhtml 和 xls2csv 根本不关心缩进:()
【问题讨论】:
标签:
excel
perl
parsing
indentation
xls
【解决方案1】:
@mapeec 链接到的网站似乎声称拥有 John McNamara 的解决方案:
#!/usr/bin/perl -w
use strict;
use Spreadsheet::ParseExcel;
my $parser = Spreadsheet::ParseExcel->new();
my $workbook = $parser->parse('Book1.xls');
if ( !defined $workbook ) {
die $parser->error(), ".\n";
}
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;
my $format = $cell->get_format();
print "Row, Col = ($row, $col)\n";
print "Value = ", $cell->value(), "\n";
print "Indent = ", $format->{Indent}, "\n";
print "\n";
}
}
}
__END__