问题描述
我最近开始在我的 Codeigniter 项目中使用 PHPWord 库。 当我尝试使用 Stackoverflow 的建议之一创建表时 - 我收到致命错误:调用未定义的方法 PHPword::addSection() 。
以下是我的控制器代码:
$this->load->library('PHPword');
$document_with_table = new PHPWord();
$section = $document_with_table->addSection();
$table = $section->addTable();
for ($r = 1; $r <= 8; $r++) {
$table->addRow();
for ($c = 1; $c <= 5; $c++) {
$table->addCell(1750)->addText("Row {$r},Cell {$c}");
}
}
// Create writer to convert document to xml
$objWriter = \PHPOffice\PHPWord\IOFactory::createWriter($document_with_table,'Word2007');
// Get all document xml code
$fullxml = $objWriter->getWriterPart('Document')->write();
// Get only table xml code
$tablexml = preg_replace('/^[\s\S]*(<w:tbl\b.*<\/w:tbl>).*/','$1',$fullxml);
//Open template with ${table}
$template_document = new \PHPOffice\PHPWord\TemplateProcessor('C:\xampp\htdocs\practice_ci\CodeIgniter\template.docx');
// Replace mark by xml code of table
$template_document->setValue('table',$tablexml);
//save template with table
$template_document->saveAs('template_with_table.docx');
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)