php - 如何在 phpword 表格的单元格中换行?

标签 php mysql phpword

我想根据数据库中存在的数据创建一个 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'));
}

最佳答案

必须先创建一个cell对象,然后使用addText

    $c1=$table->addCell(2000);
    $c1->addText("Cell 1");
    $c1->addText("New line");

关于php - 如何在 phpword 表格的单元格中换行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31768713/

相关文章:

php - 拉维 |如何确认正在使用哪个缓存驱动程序?

php - 如何根据生物识别数据的登录和注销获取工作时间?

mysql - 如何在 CodeIgniter 中为所有 SELECT 设置用户的时区

mysql - 遍历触发器中的临时表

php - 带有 PhpWord 的隐蔽 HTML:错误 - DOMDocument::loadXML():p 上的命名空间前缀 o 未在实体中定义

PHPWord:使用 Laravel 4 插入分页符并设置边距和页面方向

php - 计算数据库字段上的代码行数

java - 添加和完善PHP源代码文档的工具

javascript - 将 JSON 直接传递给 Javascript,无需 JSON.parse()

PHP Word - 添加跟踪修订