From 7ea686f6983fc3f0c0f6cc06744d9be84a05a353 Mon Sep 17 00:00:00 2001 From: Gabriel Bull Date: Thu, 13 Feb 2014 10:51:13 -0500 Subject: [PATCH] Fixed bug with table cell styles and added grid span unit tests --- Classes/PHPWord/Section/Table/Cell.php | 3 +- README.md | 27 ++++++++++++- changelog.txt | 1 + test/PHPWord/Tests/Table/CellGridSpanTest.php | 38 +++++++++++++++++++ 4 files changed, 66 insertions(+), 3 deletions(-) create mode 100644 test/PHPWord/Tests/Table/CellGridSpanTest.php diff --git a/Classes/PHPWord/Section/Table/Cell.php b/Classes/PHPWord/Section/Table/Cell.php index 4042ee4e..b4bc8242 100755 --- a/Classes/PHPWord/Section/Table/Cell.php +++ b/Classes/PHPWord/Section/Table/Cell.php @@ -80,11 +80,10 @@ class PHPWord_Section_Table_Cell $this->_insideOf = $insideOf; $this->_pCount = $pCount; $this->_width = $width; + $this->_style = new PHPWord_Style_Cell; if (!is_null($style)) { if (is_array($style)) { - $this->_style = new PHPWord_Style_Cell(); - foreach ($style as $key => $value) { if (substr($key, 0, 1) != '_') { $key = '_' . $key; diff --git a/README.md b/README.md index b9dfb003..d28be355 100755 --- a/README.md +++ b/README.md @@ -35,7 +35,9 @@ the following lines to your ``composer.json``. 1. [Basic usage](#basic-usage) 2. [Sections](#sections) * [Change Section Page Numbering](#sections-page-numbering) -3. [Images](#images) +3. [Tables](#tables) + * [Cell Style](#tables-cell-style) +4. [Images](#images) #### Basic usage @@ -83,6 +85,29 @@ $section = $PHPWord->createSection(); $section->getSettings()->setPageNumberingStart(1); ``` + +#### Tables + +The following illustrates how to create a table. + +```php +$table = $section->addTable(); +$table->addRow(); +$table->addCell(); +``` + + +##### Cell Style + +###### Cell Span + +You can span a cell on multiple columms. + +```php +$cell = $table->addCell(200); +$cell->getStyle()->setGridSpan(5); +``` + #### Images diff --git a/changelog.txt b/changelog.txt index 94eb1657..b32fd11f 100755 --- a/changelog.txt +++ b/changelog.txt @@ -24,6 +24,7 @@ Changes in branch for release 0.7.1 : - Feature: (gabrielbull) - Word2007 : Support sections page numbering +- Bugfix: (gabrielbull) - Fixed bug with cell styling Fixed in branch for release 0.7.0 : - 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 diff --git a/test/PHPWord/Tests/Table/CellGridSpanTest.php b/test/PHPWord/Tests/Table/CellGridSpanTest.php new file mode 100644 index 00000000..061f889f --- /dev/null +++ b/test/PHPWord/Tests/Table/CellGridSpanTest.php @@ -0,0 +1,38 @@ +createSection(); + + $table = $section->addTable(); + + $table->addRow(); + $cell = $table->addCell(200); + $cell->getStyle()->setGridSpan(5); + + $table->addRow(); + $table->addCell(40); + $table->addCell(40); + $table->addCell(40); + $table->addCell(40); + $table->addCell(40); + + $doc = TestHelper::getDocument($PHPWord); + $element = $doc->getElement('/w:document/w:body/w:tbl/w:tr/w:tc/w:tcPr/w:gridSpan'); + + $this->assertEquals(5, $element->getAttribute('w:val')); + } +} \ No newline at end of file