Skip to content

Commit 07b4ae2

Browse files
author
Bas-Jan 't Jong
committed
Added possiblity to add tables inside textbox
1 parent aa151c4 commit 07b4ae2

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

src/PhpWord/Element/TextBox.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,19 @@ public function getStyle()
5353
{
5454
return $this->style;
5555
}
56+
57+
/**
58+
* Add table element
59+
*
60+
* @param mixed $style
61+
* @return \PhpOffice\PhpWord\Element\Table
62+
* @todo Merge with the same function on Footer
63+
*/
64+
public function addTable($style = null)
65+
{
66+
$table = new Table($this->getDocPart(), $this->getDocPartId(), $style);
67+
$this->addElement($table);
68+
69+
return $table;
70+
}
5671
}

src/PhpWord/Writer/Word2007/Element/TextBox.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,7 @@ public function write()
5757
$margins = implode(', ', $tbxStyle->getInnerMargin());
5858
$this->xmlWriter->writeAttribute('inset', $margins);
5959
$this->xmlWriter->startElement('w:txbxContent');
60-
$this->xmlWriter->startElement('w:p');
6160
$this->parentWriter->writeContainerElements($this->xmlWriter, $this->element);
62-
$this->xmlWriter->endElement(); // w:p
6361
$this->xmlWriter->endElement(); // w:txbxContent
6462
$this->xmlWriter->endElement(); // v: textbox
6563
$styleWriter->writeW10Wrap();

src/PhpWord/Writer/Word2007/Part/AbstractPart.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public function writeContainerElements(XMLWriter $xmlWriter, AbstractElement $co
110110

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

0 commit comments

Comments
 (0)