【发布时间】:2015-08-02 18:12:58
【问题描述】:
我正在尝试使用 Perl 模块将 xlsx 转换为 xml。根据我的要求,Perl 脚本应该采用.xlsx 文件并准确转换为.xml 格式。在编译我的代码时出现错误:
print() on unopened filehandle XML at xlsxtoxml.pl.
代码:
#!/usr/bin/perl
use strict;
use warnings;
use Spreadsheet::ParseExcel;
use XML::Writer;
use Spreadsheet::XLSX;
my $excel = Spreadsheet::XLSX -> new ('Template.xlsx');
foreach my $sheet (@{$excel -> {Worksheet}}) {
$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) {
#print XML $cell -> {Val};
}
unless($col == $sheet -> {MaxCol}) {print XML ",";}
}
unless( $row == $sheet -> {MaxRow}){print XML "\n";}
}
}
close(XML);
my $xml_obj = XML::Writer->new();
$xml_obj->print_xml("outTemplate.xml");
【问题讨论】:
-
请建议我修改代码,并为我的要求提供更好的 perl 模块...提前谢谢
标签: xml perl perl-module perl-data-structures