【发布时间】:2015-10-15 08:01:13
【问题描述】:
我正在使用 Perl 脚本编写一个 Excel 电子表格,如果不存在数据,我需要将特定行的行高设置为“0”。这是我到目前为止所写的一些内容。它适用于基于文本文件写入数据,但如果该项目不在文本文件中,那么它会留下一个我想消除的空行。任何帮助表示赞赏。
my $file = 'forecast.txt';
open my $fh, '<', $file or die "Could not open '$file' $!\n";
while (my $line =<$fh>) {
if (index($line, 'M1501235') != -1) {
$worksheet->write(11,0, "M1501", $print2);
$worksheet->write(11,1, "FUND TO FUND TRANSFERS", $print);
$worksheet->write(11,2, "DES", $print);
$worksheet->write(11,3, "0001", $print);
$worksheet->write(11,4, "", $print);
$worksheet->write(11,5, "NA", $print);
$worksheet->write(11,6, "SEE RH", $print);
}
# else $worksheet->set_row (11, 0);
if (index($line, 'M2201235') != -1) {
$worksheet->write(12,0, "M2201", $print2);
$worksheet->write(12,1, "BPS FUND BALANCE ERROR RPT", $print);
$worksheet->write(12,2, "L&I", $print);
$worksheet->write(12,3, "0010", $print);
$worksheet->write(12,4, "", $print);
$worksheet->write(12,5, "NA", $print);
$worksheet->write(12,6, "2 COPIES 37", $print);
}
else $worksheet->set_row ($_, 0) for (0..11);
elsif (index($line, 'M2301235') != -1) {
$worksheet->write(13,0, "M2201", $print2);
$worksheet->write(13,1, "BPS/ARC RECOCILIATION RPT/BPS CREDIT BALANCE RPT", $print);
$worksheet->write(13,2, "L&I", $print);
$worksheet->write(13,3, "0010", $print);
$worksheet->write(13,4, "", $print);
$worksheet->write(13,5, "NA", $print);
$worksheet->write(13,6, "2 COPIES 37", $print);
}
}
【问题讨论】:
-
您使用的是哪个库?是 Excel::Writer::XLSX 吗?
标签: excel perl spreadsheet