How to make the table in word using PHPWord which includes multiple rowspan and colspan?

蹲街弑〆低调 提交于 2019-11-28 04:07:55

问题


I have been learning the PHPWord for my academic project, and I also have the latest PHPWord library which supports "vMerge" for rowspan and "gridSpan" for colspan.

I have been finding difficulty in creating one particular type of table structure as shown in the Image below.

The problem is how to have same rowspan for '1','2' and '6' , in this case it is equal to 2.

Any kind of help would be appreciated.

edit-1 I have succeeded with basic rowspan and colspan, but I am finding difficulty with this complex table.


回答1:


There is an example in the samples that is quite close to what you are doing: https://github.com/PHPOffice/PHPWord/blob/develop/samples/Sample_09_Tables.php

and modifying that a bit to achieve your example:

$cellRowSpan = array('vMerge' => 'restart');
$cellRowContinue = array('vMerge' => 'continue');
$cellColSpan = array('gridSpan' => 2);

$table->addRow();
$table->addCell(2000, $cellRowSpan)->addText("1");
$table->addCell(2000, $cellRowSpan)->addText("2");
$table->addCell(4000, $cellColSpan)->addText("3");
$table->addCell(2000, $cellRowSpan)->addText("6");

$table->addRow();
$table->addCell(null, $cellRowContinue);
$table->addCell(null, $cellRowContinue);
$table->addCell(2000)->addText("4");
$table->addCell(2000)->addText("5");
$table->addCell(null, $cellRowContinue);

$table->addRow();
$table->addCell(2000);
$table->addCell(2000);
$table->addCell(2000);
$table->addCell(2000);
$table->addCell(2000);

tested with 0.13.0 version (for some reason libreoffice didn't like the two adjecent cells with vMerge continue definitions and didn't display them as expected, but word did display them nicely as expected)



来源:https://stackoverflow.com/questions/38124184/how-to-make-the-table-in-word-using-phpword-which-includes-multiple-rowspan-and

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!