您好我正在尝试在这样的函数中使用PHPword mehods:
function export(){
require_once 'PHPWord.php';
$PHPWord = new PHPWord();
$section = $PHPWord->createSection();
$section->addText('Hello world!');
$section->addText('Hello world! I am formatted.', array('name'=>'Tahoma', 'size'=>16, 'bold'=>true));
$PHPWord->addFontStyle('myOwnStyle', array('name'=>'Verdana', 'size'=>14, 'color'=>'1B2232'));
$section->addText('Hello world! I am formatted by a user defined style', 'myOwnStyle');
$myTextElement = $section->addText('Hello World!');
$myTextElement->setBold();
$myTextElement->setName('Verdana');
$myTextElement->setSize(22);
$table = $section->addTable();
$table->addRow(900);
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007');
$objWriter->save('helloWorld.docx');
}
我需要函数内部的PHPword.php文件,一切正常,直到我使用$table->addRow(900);
方法,此后函数返回错误。我不知道错误类型,因为服务器上的php错误已关闭。仅当代码在函数内部时才会发生这种情况。如果它不在函数中相同的代码工作正常。
我打开了错误显示,生成的文件中包含错误文本:Fatal error: Call to a member function getSettings() on a non-object in PHPWord\Writer\Word2007\Base.php on line 396.
我还发现错误发生在:$objWriter->save('helloWorld.docx');
行。预防它可以防止崩溃,但不会保存任何东西。可能是什么问题?