Skip to content

Commit 7ea686f

Browse files
committed
Fixed bug with table cell styles and added grid span unit tests
1 parent f76a9cd commit 7ea686f

File tree

4 files changed

+66
-3
lines changed

4 files changed

+66
-3
lines changed

Classes/PHPWord/Section/Table/Cell.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,10 @@ public function __construct($insideOf, $pCount, $width = null, $style = null)
8080
$this->_insideOf = $insideOf;
8181
$this->_pCount = $pCount;
8282
$this->_width = $width;
83+
$this->_style = new PHPWord_Style_Cell;
8384

8485
if (!is_null($style)) {
8586
if (is_array($style)) {
86-
$this->_style = new PHPWord_Style_Cell();
87-
8887
foreach ($style as $key => $value) {
8988
if (substr($key, 0, 1) != '_') {
9089
$key = '_' . $key;

README.md

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ the following lines to your ``composer.json``.
3535
1. [Basic usage](#basic-usage)
3636
2. [Sections](#sections)
3737
* [Change Section Page Numbering](#sections-page-numbering)
38-
3. [Images](#images)
38+
3. [Tables](#tables)
39+
* [Cell Style](#tables-cell-style)
40+
4. [Images](#images)
3941

4042
<a name="basic-usage"></a>
4143
#### Basic usage
@@ -83,6 +85,29 @@ $section = $PHPWord->createSection();
8385
$section->getSettings()->setPageNumberingStart(1);
8486
```
8587

88+
<a name="tables"></a>
89+
#### Tables
90+
91+
The following illustrates how to create a table.
92+
93+
```php
94+
$table = $section->addTable();
95+
$table->addRow();
96+
$table->addCell();
97+
```
98+
99+
<a name="tables-cell-style"></a>
100+
##### Cell Style
101+
102+
###### Cell Span
103+
104+
You can span a cell on multiple columms.
105+
106+
```php
107+
$cell = $table->addCell(200);
108+
$cell->getStyle()->setGridSpan(5);
109+
```
110+
86111
<a name="images"></a>
87112
#### Images
88113

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
Changes in branch for release 0.7.1 :
2626
- Feature: (gabrielbull) - Word2007 : Support sections page numbering
27+
- Bugfix: (gabrielbull) - Fixed bug with cell styling
2728

2829
Fixed in branch for release 0.7.0 :
2930
- Bugfix: (RomanSyroeshko) GH-32 - "Warning: Invalid error type specified in ...\PHPWord.php on line 226" is thrown when the specified template file is not found
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
namespace PHPWord\Tests\Table;
3+
4+
use PHPUnit_Framework_TestCase;
5+
use PHPWord;
6+
use PHPWord\Tests\TestHelper;
7+
8+
class CellGridSpanTest extends PHPUnit_Framework_TestCase
9+
{
10+
public function tearDown()
11+
{
12+
TestHelper::clear();
13+
}
14+
15+
public function testCellGridSpan()
16+
{
17+
$PHPWord = new PHPWord();
18+
$section = $PHPWord->createSection();
19+
20+
$table = $section->addTable();
21+
22+
$table->addRow();
23+
$cell = $table->addCell(200);
24+
$cell->getStyle()->setGridSpan(5);
25+
26+
$table->addRow();
27+
$table->addCell(40);
28+
$table->addCell(40);
29+
$table->addCell(40);
30+
$table->addCell(40);
31+
$table->addCell(40);
32+
33+
$doc = TestHelper::getDocument($PHPWord);
34+
$element = $doc->getElement('/w:document/w:body/w:tbl/w:tr/w:tc/w:tcPr/w:gridSpan');
35+
36+
$this->assertEquals(5, $element->getAttribute('w:val'));
37+
}
38+
}

0 commit comments

Comments
 (0)