-5

下面是我的代码:

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 中。

4

1 回答 1

2

您的代码实际上对我有用(对您的示例中未定义的“$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(无特殊格式)

也许您应该$workbook->close;在代码末尾添加?

希望能帮助到你。

于 2013-10-24T21:07:54.383 回答