以下是我的代码:
use Spreadsheet::WriteExcel;
my @worksheet ;
my($server_count) = 0;
my($row) = 0;
$worksheet[$server_count] = $workbook->addworksheet("Break Summary");
$worksheet[$server_count]->set_column(0, 0, 60);
$worksheet[$server_count]->set_column(1, 1, 20);
$worksheet[$server_count]->write_string($row, 0, "PositionsSTB" ,$summary_title_format);
$worksheet[$server_count]->write_string(++$row, 0, "Number of distinct accounts breaking" ,$general_format);
&log_info ("\nPOS 0 $break_summary_excel_results[0]");
$worksheet[$server_count]->write_number($row, 1, $break_summary_excel_results[0] ,$general_format);
它打印信息以记录,但不打印到Excel。
答案 0 :(得分:1)
您的代码实际上适用于我(稍微更改了您的示例中未定义的“$ format”变量)。这是我的整个测试文件:
#! /usr/bin/perl
use Spreadsheet::WriteExcel;
my @worksheet;
my $server_count = 0;
my $row = 0;
my $workbook = Spreadsheet::WriteExcel->new('excel_file.xls');
my $format = $workbook->add_format();
$format->set_bold();
$format->set_color('red');
$format->set_align('center');
$worksheet[$server_count] = $workbook->addworksheet("Break Summary");
$worksheet[$server_count]->set_column(0, 0, 60);
$worksheet[$server_count]->set_column(1, 1, 20);
$worksheet[$server_count]->write_string($row, 0, "PositionsSTB" ,$format);
$worksheet[$server_count]->write_string(++$row, 0, "Number of distinct accounts breaking");
$worksheet[$server_count]->write_number($row, 1, $break_summary_excel_results[0] ,$general_format);
我在linux上使用Spreadsheet :: WriteExcel版本2.37。在我的例子中,上面代码的输出是长度为5632字节的Excel文件“excel_file.xls”,包含1个工作表(“Break Summary”)和3个单元格:
A1:“PositionsSTB”(居中,红色,粗体) A2:“不同账户数量突破”(无规格格式) B2:0(没有specjal格式)
也许你在代码的末尾添加$workbook->close;
?
希望它有所帮助。