@@ -295,6 +295,23 @@ public function addCheckBox($name, $text, $fontStyle = null, $paragraphStyle = n
295295 return $ element ;
296296 }
297297
298+ /**
299+ * Add textbox element
300+ *
301+ * @param mixed $style
302+ * @return \PhpOffice\PhpWord\Element\TextBox
303+ */
304+ public function addTextBox ($ style = null )
305+ {
306+ $ this ->checkValidity ('TextBox ' );
307+
308+ $ textbox = new TextBox ($ style );
309+ $ textbox ->setDocPart ($ this ->getDocPart (), $ this ->getDocPartId ());
310+ $ this ->addElement ($ textbox );
311+
312+ return $ textbox ;
313+ }
314+
298315 /**
299316 * Check if a method is allowed for the current container
300317 *
@@ -304,7 +321,7 @@ public function addCheckBox($name, $text, $fontStyle = null, $paragraphStyle = n
304321 private function checkValidity ($ method )
305322 {
306323 // Valid containers for each element
307- $ allContainers = array ('section ' , 'header ' , 'footer ' , 'cell ' , 'textrun ' , 'footnote ' , 'endnote ' );
324+ $ allContainers = array ('section ' , 'header ' , 'footer ' , 'cell ' , 'textrun ' , 'footnote ' , 'endnote ' , ' textbox ' );
308325 $ validContainers = array (
309326 'Text ' => $ allContainers ,
310327 'Link ' => $ allContainers ,
@@ -314,6 +331,7 @@ private function checkValidity($method)
314331 'TextRun ' => array ('section ' , 'header ' , 'footer ' , 'cell ' ),
315332 'ListItem ' => array ('section ' , 'header ' , 'footer ' , 'cell ' ),
316333 'CheckBox ' => array ('section ' , 'header ' , 'footer ' , 'cell ' ),
334+ 'TextBox ' => array ('section ' , 'header ' , 'footer ' ),
317335 'Footnote ' => array ('section ' , 'textrun ' , 'cell ' ),
318336 'Endnote ' => array ('section ' , 'textrun ' , 'cell ' ),
319337 'PreserveText ' => array ('header ' , 'footer ' , 'cell ' ),
@@ -352,7 +370,7 @@ private function checkValidity($method)
352370 */
353371 private function checkElementDocPart ()
354372 {
355- $ isCellTextrun = in_array ($ this ->container , array ('cell ' , 'textrun ' ));
373+ $ isCellTextrun = in_array ($ this ->container , array ('cell ' , 'textrun ' , ' textbox ' ));
356374 $ docPart = $ isCellTextrun ? $ this ->getDocPart () : $ this ->container ;
357375 $ docPartId = $ isCellTextrun ? $ this ->getDocPartId () : $ this ->sectionId ;
358376 $ inHeaderFooter = ($ docPart == 'header ' || $ docPart == 'footer ' );
0 commit comments