任何人都可以帮助我编写一个 perl 脚本,用于从提供的 .xls/.csv 文件创建 .xml ......
我正在尝试下面的代码......它根本不工作......
#!/usr/bin/perl
use strict;
use warnings;
use Spreadsheet::ParseExcel;
use XML::Writer ();
use XML::Writer::String ();
use IO::File;
use File::Find;
print"Enter1";
my $parser = Spreadsheet::ParseExcel->new();
my $workbook = $parser->parse('C:\Users\uidw3321\Desktop\one.xls');
if ( !defined $workbook ) {
die $parser->error(), ".\n";
}
my $xml_doc = XML::Writer::String->new();
my $xml_file = new IO::File(">D:\\tmp\\bmw.xml");
my $xml_doc_writer = new XML::Writer(OUTPUT => $xml_file);
for my $worksheet ( $workbook->worksheets() ) {
my ( $row_min, $row_max ) = $worksheet->row_range();
my ( $col_min, $col_max ) = $worksheet->col_range();
my %headers = ();
for my $row ( $row_min .. $row_max ) {
for my $col ( $col_min .. $col_max ) {
my $cell = $worksheet->get_cell( $row, $col );
if ($row == 0) {
$headers{$col} = $cell->unformatted();
} else {
$xml_doc_writer->dataElement($headers{$col},$cell->unformatted());
}
}
}
}
$xml_doc_writer->end();
$xml_file->close();
请帮忙