Note that there are some explanatory texts on larger screens.

plurals
  1. POPHPWord export giving Corrupt Word File
    primarykey
    data
    text
    <p>I used the example code from PHPWord's site: <a href="http://phpword.codeplex.com/documentation" rel="nofollow">http://phpword.codeplex.com/documentation</a> And when I try and open it with Word I get the error "The Office Open XML file test.docx cannot be opened because there are problems with the contents." and when I click "Details" It simply says "The file is corrupt and cannot be opened." It does let me repair it and open it, but that wouldn't be very user friendly... Here is the code I'm using: <pre><code>// Create a new PHPWord Object $PHPWord = new PHPWord(); // Every element you want to append to the word document is placed in a section. So you need a section: $section = $PHPWord-&gt;createSection(); // After creating a section, you can append elements: $section-&gt;addText('Hello world!'); // You can directly style your text by giving the addText function an array: $section-&gt;addText('Hello world! I am formatted.', array('name'=&gt;'Tahoma', 'size'=&gt;16, 'bold'=&gt;true)); // If you often need the same style again you can create a user defined style to the word document // and give the addText function the name of the style&gt;: $PHPWord-&gt;addFontStyle('myOwnStyle', array('name'=&gt;'Verdana', 'size'=&gt;14, 'color'=&gt;'1B2232')); $section-&gt;addText('Hello world! I am formatted by a user defined style', 'myOwnStyle'); // You can also putthe appended element to local object an call functions like this: $myTextElement = $section-&gt;addText('Hello World!'); header('Content-Type: application/vnd.ms-word'); header('Content-Disposition: attachment;filename="test.docx"'); header('Cache-Control: max-age=0'); // At least write the document to webspace: $objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007'); $objWriter-&gt;save('php://output'); </code></pre> <p>As you can see I did use php://output as the save there. Any ideas on how to get rid of the corruption. I did open the zip and saw that at the end of document.xml it appears there is blank line. Maybe that is causing it?</p> <p>Thanks!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload