Skip to content

Commit 4954f28

Browse files
committed
Merge pull request PHPOffice#807 from githubjeka/patch-1
Update Sample_09_Tables.php
2 parents 38ca52e + d3f3a4a commit 4954f28

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

samples/Sample_09_Tables.php

+35-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,41 @@
9191
$table->addCell(2000, $cellVCentered)->addText(htmlspecialchars('D', ENT_COMPAT, 'UTF-8'), null, $cellHCentered);
9292
$table->addCell(null, $cellRowContinue);
9393

94-
// 4. Nested table
94+
/**
95+
* 4. colspan (gridSpan) and rowspan (vMerge)
96+
* ---------------------
97+
* | | B | 1 |
98+
* | A | |----|
99+
* | | | 2 |
100+
* | |---|----|----|
101+
* | | C | D | 3 |
102+
* ---------------------
103+
* @see https://github.com/PHPOffice/PHPWord/issues/806
104+
*/
105+
$section->addPageBreak();
106+
$section->addText(htmlspecialchars('Table with colspan and rowspan', ENT_COMPAT, 'UTF-8'), $header);
107+
108+
$styleTable = ['borderSize' => 6, 'borderColor' => '999999'];
109+
$phpWord->addTableStyle('Colspan Rowspan', $styleTable);
110+
$table = $section->addTable('Colspan Rowspan');
111+
112+
$row = $table->addRow();
113+
114+
$row->addCell(null, ['vMerge' => 'restart'])->addText('A');
115+
$row->addCell(null, ['gridSpan' => 2, 'vMerge' => 'restart',])->addText('B');
116+
$row->addCell()->addText('1');
117+
118+
$row = $table->addRow();
119+
$row->addCell(null, ['vMerge' => 'continue']);
120+
$row->addCell(null, ['vMerge' => 'continue','gridSpan' => 2,]);
121+
$row->addCell()->addText('2');
122+
$row = $table->addRow();
123+
$row->addCell(null, ['vMerge' => 'continue']);
124+
$row->addCell()->addText('C');
125+
$row->addCell()->addText('D');
126+
$row->addCell()->addText('3');
127+
128+
// 5. Nested table
95129

96130
$section->addTextBreak(2);
97131
$section->addText(htmlspecialchars('Nested table in a centered and 50% width table.', ENT_COMPAT, 'UTF-8'), $header);

0 commit comments

Comments
 (0)