.xlsx ファイルを .xml ファイルに変換しようとしています。.xlsx ファイルの最初の行 (見出し) は、xml ファイルのタグになります。
私は正常に動作しているコードの下に書いています-
open(XML, ">temp.csv") or die "not able to open $!";
use Spreadsheet::XLSX;
my $excel = Spreadsheet::XLSX -> new ('test.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);
use XML::CSV;
my $csv_obj = XML::CSV->new();
$csv_obj->parse_doc("temp.csv", {headings => 1});
$csv_obj->print_xml("out.xml");
大きな.xlsxファイルを処理する必要があるため、誰でもより良いコード(モジュール)を提案できますか?
前もって感謝します。
おとこ