Spreadsheet::WriteExcel 未使用 merge_range 在 Excel 中写入字符串
我正在使用 Spreadsheet::WriteExcel
创建一个 Excel 并向其中写入一些数据。 我正在使用 merge_range
来合并一些单元格。 但问题是我的下面的代码确实合并了单元格,但不显示其中的数据($str
内容)。 我无法弄清楚为什么????。
请帮帮我,我哪里出错了?
以下是我的代码的一部分:
#!/usr/bin/perl
use Spreadsheet::WriteExcel;
use strict;
my $wb = Spreadsheet::WriteExcel->new('excel_test.xls');
my $custom_ws = $wb->add_worksheet('Custom Parameters');
my $wb_format_merge = $wb->add_format();
$wb_format_merge->set_bold();
$wb_format_merge->set_text_wrap();
$wb_format_merge->set_border(1);
$wb_format_merge->set_align('left');
$wb_format_merge->set_valign('vcenter');
my($row, $coll) = 0;
my $merge_coll_len = 8;
###### write data ###
my $str = "Please select the follwong metrics to generate custom report in Details sheet";
$custom_ws->merge_range($row, $coll, $row, $coll + $merge_coll_len, $str,$merge_format);
$row += 2;
$custom_ws->write($row, $coll, 'select the data type for the reference');
I am using Spreadsheet::WriteExcel
to create an excel and write some data into it.
I am using the merge_range
to merger some cells.
But the problem is my below code does merge cells but dont show the data in it ($str
contents).
I am not able to figure out why????.
Please help me, where did i going wrong?
Below is the part of my code:
#!/usr/bin/perl
use Spreadsheet::WriteExcel;
use strict;
my $wb = Spreadsheet::WriteExcel->new('excel_test.xls');
my $custom_ws = $wb->add_worksheet('Custom Parameters');
my $wb_format_merge = $wb->add_format();
$wb_format_merge->set_bold();
$wb_format_merge->set_text_wrap();
$wb_format_merge->set_border(1);
$wb_format_merge->set_align('left');
$wb_format_merge->set_valign('vcenter');
my($row, $coll) = 0;
my $merge_coll_len = 8;
###### write data ###
my $str = "Please select the follwong metrics to generate custom report in Details sheet";
$custom_ws->merge_range($row, $coll, $row, $coll + $merge_coll_len, $str,$merge_format);
$row += 2;
$custom_ws->write($row, $coll, 'select the data type for the reference');
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
$coll
未定义use
my($row, $coll)=(0,0);
使用 4 row,coll,row,coll 作为
merge_range< /code> 完全有效(只要它们有值;))
$coll
is undefineduse
my($row, $coll)=(0,0);
Using 4 row,coll,row,coll for the
merge_range
is perfectly valid (provided they have values ;) )从我在
Spreadsheet::WriteExcel
文档中可以看到例如,单元格范围应该作为单个字符串参数传递,尽管正如约翰指出的那样,单独的参数也是有效的:对于单个参数形式,它看起来像这样:
一个想法可能是滚动几个助手子程序允许使用这种形式:
然后调用
range
:From what I can see in the
Spreadsheet::WriteExcel
documentation example, the cell ranges are supposed to be passed as a single string argument, although as John points out, separate arguments are valid also:For the single argument form, it would look like this:
One idea could be to roll a couple of helper subroutines to allow for the use of this form:
And then call
range
: