This project is read-only.

'Basic example' not so basic...?

Sep 8, 2010 at 8:19 AM


I've downloaded the classes, and run the 'Basic example' from the documentation.  I'm getting an error on these three lines:

$myTextElement->setBold(); $myTextElement->setName('Verdana'); $myTextElement->setSize(22);


The error is: "Call to undefined method PHPWord_Section_Text::setBold()" for each one.  If they are commented out the document is written and saved with no error.


Then, when I try to open the document, I can't since it is "corrupted".  Details>>> says "A document must contain exactly one root element."


Similar problem in 'Examples' folder: I can open 'test.docx' just fine.  Then run the 'test.php' script in the 'Examples' folder with no error.  Then re-open 'test.docx' -> file corrupted. Details>>>Incorrect Processing Instruction Syntax.


I'm working with Word 2010 x64.  Any insights?  Thanks in advance.


(Running PHP 5.2.8 on an Apache 2.2, Win 7 Ultimate x64)

Sep 27, 2010 at 3:57 PM

Hi Hermes,

The example is almost complete. It's just that in one class the Style object is not defined properly. My bugfix was to:

- Edit Section/Text.php and replace line 77 with:
          $this->_styleFont = new PHPWord_Style_Font('text');
- Edit PHPWord.php and replace all occurencese of $myTextElement with $myTextElement->getFontStyle() to get the Style object, so the line you are complaining about would become:

Best regards,