Excel :: Writer :: XLSX:无法将传递的工作表中的某些单元格写入

时间:2019-03-04 18:53:20

标签: excel perl xlsx

我是一个工作簿,我希望将其传递给各个子项目,每个子项目都写入同一工作表。第一个子将创建工作表并编写一些列,其他子将添加更多列并填充这些列中的单元格。我观察到的是,某些单元不能被其他子单元写入,如下所示:

sub SubOne
{
    my ($workbook) = @_;

    my $worksheet = $workbook->add_worksheet("Startup");
    my $formatHead = $workbook->add_format();
    $formatHead->set_bold();
    $formatHead->set_align('center');
    $formatHead->set_bg_color('yellow');

    my $formatContents = $workbook->add_format();
    $formatContents->set_align('center');

    $worksheet->set_tab_color('Red');
    $worksheet->set_column('A:A', 11);
    $worksheet->set_column('B:B', 15);
    $worksheet->set_column('C:C', 15);
    $worksheet->set_column('D:D', 24);
    $worksheet->write(0, 0, "column0", $formatHead);
    $worksheet->write(0, 1, "column1", $formatHead);
    $worksheet->write(0, 2, "column2", $formatHead);
    $worksheet->write(0, 3, "column3", $formatHead);
    #Fill the columns with data
}

这一切都很好。创建带有标题的四列,并在其中包含数据。假设每列下有3行数据。一切正常。然后像下面的示例一样调用另一个子程序:

sub SubTwo
{
    my ($workbook) = @_;

    my $worksheet3 = $workbook->sheets(0);

    my $formatHead = $workbook->add_format();
    $formatHead->set_bold();
    $formatHead->set_align('center');
    $formatHead->set_bg_color('yellow');

    my $formatContents = $workbook->add_format();
    $formatContents->set_align('center');

    $worksheet3->write(0, 4, "column4", $formatHead );
    $worksheet3->write(0, 5, "column5", $formatHead );
    $worksheet3->write(6, 6, "test1", $formatContents);
    $worksheet3->write(7, 7, "test2", $formatHead);
    $worksheet3->write(1, 8, "test3", $formatHead);
    $worksheet3->write(7, 1, "test4", $formatContents);
}

其中仅写入test1,test2,test4。它们在正确的单元格中。好像无法将任何内容写入到先前子SubOne已写入的行中。为什么要锁定行以防止进一步写入?

编辑:修复了关闭set_optimization()的问题。

0 个答案:

没有答案