我想从数据库中存在的数据创建一个word文件.docx.
为了完成这项工作,我使用的是PHPword 0.12.0.
我需要绘制一个表来将数据放入其中.之后我需要从数据库中的表中获取每一行以自动进入新行的单元格.
我可以做这个工作
$section->addTextBreak();
但是没有桌子,现在我怎样才能在桌子内的单元格中完成这项工作?
我使用下面的代码,但它不起作用.
$area=array();
$axis=array();
$topic=array();
$table->addRow(900);
$table->addCell(2000, $styleCell)->addText(htmlspecialchars('test1'), $fontStyle);
$table->addCell(2000, $styleCell)->addText(htmlspecialchars('test2'), $fontStyle);
$table->addCell(2000, $styleCell)->addText(htmlspecialchars('test3'), $fontStyle);
$table->addCell(2000, $styleCell)->addText(htmlspecialchars('test4'), $fontStyle);
for ($i = 0; $i < 4; $i++) {
$table->addRow();
$table->addCell(2000)->addText(htmlspecialchars($topic{$i}),array('name' => 'Segoe UI Semilight'));
$table->addCell(3000)->addText(htmlspecialchars($axis{$i}),array('rtl' => true,'name' => 'Segoe UI Semilight'));
$table->addCell(2000)->addText(htmlspecialchars($area{$i}),array('rtl' => true,'name' => 'Segoe UI Semilight'));
$table->addCell(2000)->addText(htmlspecialchars($i),array('rtl' => true,'name' => 'Segoe UI Semilight'));
}
解决方法:
您必须首先创建一个单元格对象,然后使用addText
$c1=$table->addCell(2000);
$c1->addText("Cell 1");
$c1->addText("New line");
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。