, и когда я пытаюсь открыть его с помощью слова, я получаю ошибку «Офис открывает тест XML -файла. Докс не может быть открыт, потому что есть проблемы с содержанием». И когда я нажимаю «Подробности», он просто говорит: «Файл поврежден и не может быть открыт». Это позволяет мне восстановить его и открыть, но это не было бы очень удобным для пользователя ... вот код, который я использую:
Код: Выделить всё
// 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->createSection();
// After creating a section, you can append elements:
$section->addText('Hello world!');
// You can directly style your text by giving the addText function an array:
$section->addText('Hello world! I am formatted.', array('name'=>'Tahoma', 'size'=>16, 'bold'=>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>:
$PHPWord->addFontStyle('myOwnStyle', array('name'=>'Verdana', 'size'=>14, 'color'=>'1B2232'));
$section->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->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->save('php://output');
Спасибо! < /P>
Подробнее здесь: https://stackoverflow.com/questions/857 ... -word-file
Мобильная версия