PHPWord text wrap is simple: $ PHPWord = newPHPWord (); $ section = $ PHPWord-& amp; gt; createSection (); $ section-& amp; gt;
PHPWord text line feed is simple:
$ PHPWord = new PHPWord (); $ section = $ PHPWord-> createSection (); $ section-> addText ('php point-through-www.phpddt.com '); $ section-> addTextBreak (1); // line feed
However, there seems to be no corresponding method to wrap a line in the cell cells added to the table. the PHPWord solution is as follows:
Replace the _ writeText () method in phpword/writer/word2007/base. php with the following:
Protected function _ writeText (PHPWord_Shared_XMLWriter $ objWriter = null, PHPWord_Section_Text $ text, $ withoutP = false) {$ styleFont = $ text-> getFontStyle (); $ SfIsObject = ($ styleFont instanceof PHPWord_Style_Font )? True: false; // @ blog
$ StrText = htmlspecialchars ($ text-> getText (); // divide the text into an array using \ n $ str_tmp = explode ("\ n", $ strText ); // cyclically output array text for ($ I = 0; $ I <count ($ str_tmp); $ I ++) {if (! $ WithoutP) {$ objWriter-> startElement ('W: P'); $ styleParagraph = $ text-> getParagraphStyle (); $ SpIsObject = ($ styleParagraph instanceof objects )? True: false; if ($ SpIsObject) {$ this-> _ writeParagraphStyle ($ objWriter, $ styleParagraph);} elseif (! $ SpIsObject &&! Is_null ($ styleParagraph) {$ objWriter-> startElement ('W: ppr'); $ objWriter-> startElement ('W: pstyle '); $ objWriter-> writeAttribute ('W: val ', $ styleParagraph); $ objWriter-> endElement ();}} $ strText = htmlspecialchars ($ text-> getText (); $ strText = PHPWord_Shared_String: ControlCharacterPHP2OOXML ($ strText); $ strText = $ str_tmp [$ I]; $ strText = PHPWord_Shared_String: ControlCharacterPHP2OOX ML ($ strText); $ objWriter-> startElement ('W: r'); if ($ SfIsObject) {$ this-> _ writeTextStyle ($ objWriter, $ styleFont );} elseif (! $ SfIsObject &&! Is_null ($ styleFont) {$ objWriter-> startElement ('W: rpr'); $ objWriter-> startElement ('W: rstyle '); $ objWriter-> writeAttribute ('W: val ', $ styleFont); $ objWriter-> endElement ();} $ objWriter-> startElement ('W: t'); $ objWriter-> writeAttribute ('XML: space', 'preserv '); // needed because of drawing spaces before and after text $ objWriter-> writeRaw ($ strText); $ objWriter-> endElement (); $ objWriter-> EndElement (); // w: rif (! $ WithoutP) {$ objWriter-> endElement (); // w: p }}}
This is an official example. if you have any good solutions, please leave a message!