Skip to content

Commit

Permalink
Added possiblity to add tables inside textbox
Browse files Browse the repository at this point in the history
  • Loading branch information
Bas-Jan 't Jong committed May 10, 2014
1 parent aa151c4 commit 07b4ae2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
15 changes: 15 additions & 0 deletions src/PhpWord/Element/TextBox.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,19 @@ public function getStyle()
{
return $this->style;
}

/**
* Add table element
*
* @param mixed $style
* @return \PhpOffice\PhpWord\Element\Table
* @todo Merge with the same function on Footer
*/
public function addTable($style = null)
{
$table = new Table($this->getDocPart(), $this->getDocPartId(), $style);
$this->addElement($table);

return $table;
}
}
2 changes: 0 additions & 2 deletions src/PhpWord/Writer/Word2007/Element/TextBox.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,7 @@ public function write()
$margins = implode(', ', $tbxStyle->getInnerMargin());
$this->xmlWriter->writeAttribute('inset', $margins);
$this->xmlWriter->startElement('w:txbxContent');
$this->xmlWriter->startElement('w:p');
$this->parentWriter->writeContainerElements($this->xmlWriter, $this->element);
$this->xmlWriter->endElement(); // w:p
$this->xmlWriter->endElement(); // w:txbxContent
$this->xmlWriter->endElement(); // v: textbox
$styleWriter->writeW10Wrap();
Expand Down
2 changes: 1 addition & 1 deletion src/PhpWord/Writer/Word2007/Part/AbstractPart.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public function writeContainerElements(XMLWriter $xmlWriter, AbstractElement $co

// Loop through elements
$elements = $container->getElements();
$withoutP = in_array($containerName, array('TextRun', 'Footnote', 'Endnote', 'TextBox')) ? true : false;
$withoutP = in_array($containerName, array('TextRun', 'Footnote', 'Endnote')) ? true : false;
if (count($elements) > 0) {
foreach ($elements as $element) {
if ($element instanceof AbstractElement) {
Expand Down

0 comments on commit 07b4ae2

Please sign in to comment.