Fixed bug with table cell styles and added grid span unit tests

This commit is contained in:
Gabriel Bull 2014-02-13 10:51:13 -05:00
parent f76a9cdbed
commit 7ea686f698
4 changed files with 66 additions and 3 deletions

View File

@ -80,11 +80,10 @@ class PHPWord_Section_Table_Cell
$this->_insideOf = $insideOf; $this->_insideOf = $insideOf;
$this->_pCount = $pCount; $this->_pCount = $pCount;
$this->_width = $width; $this->_width = $width;
$this->_style = new PHPWord_Style_Cell;
if (!is_null($style)) { if (!is_null($style)) {
if (is_array($style)) { if (is_array($style)) {
$this->_style = new PHPWord_Style_Cell();
foreach ($style as $key => $value) { foreach ($style as $key => $value) {
if (substr($key, 0, 1) != '_') { if (substr($key, 0, 1) != '_') {
$key = '_' . $key; $key = '_' . $key;

View File

@ -35,7 +35,9 @@ the following lines to your ``composer.json``.
1. [Basic usage](#basic-usage) 1. [Basic usage](#basic-usage)
2. [Sections](#sections) 2. [Sections](#sections)
* [Change Section Page Numbering](#sections-page-numbering) * [Change Section Page Numbering](#sections-page-numbering)
3. [Images](#images) 3. [Tables](#tables)
* [Cell Style](#tables-cell-style)
4. [Images](#images)
<a name="basic-usage"></a> <a name="basic-usage"></a>
#### Basic usage #### Basic usage
@ -83,6 +85,29 @@ $section = $PHPWord->createSection();
$section->getSettings()->setPageNumberingStart(1); $section->getSettings()->setPageNumberingStart(1);
``` ```
<a name="tables"></a>
#### Tables
The following illustrates how to create a table.
```php
$table = $section->addTable();
$table->addRow();
$table->addCell();
```
<a name="tables-cell-style"></a>
##### Cell Style
###### Cell Span
You can span a cell on multiple columms.
```php
$cell = $table->addCell(200);
$cell->getStyle()->setGridSpan(5);
```
<a name="images"></a> <a name="images"></a>
#### Images #### Images

View File

@ -24,6 +24,7 @@
Changes in branch for release 0.7.1 : Changes in branch for release 0.7.1 :
- Feature: (gabrielbull) - Word2007 : Support sections page numbering - Feature: (gabrielbull) - Word2007 : Support sections page numbering
- Bugfix: (gabrielbull) - Fixed bug with cell styling
Fixed in branch for release 0.7.0 : 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 - 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

View File

@ -0,0 +1,38 @@
<?php
namespace PHPWord\Tests\Table;
use PHPUnit_Framework_TestCase;
use PHPWord;
use PHPWord\Tests\TestHelper;
class CellGridSpanTest extends PHPUnit_Framework_TestCase
{
public function tearDown()
{
TestHelper::clear();
}
public function testCellGridSpan()
{
$PHPWord = new PHPWord();
$section = $PHPWord->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'));
}
}