【问题标题】:how to add table in phpword with laravel如何使用 laravel 在 phpword 中添加表格
【发布时间】:2020-05-13 11:50:38
【问题描述】:

我正在尝试使用 laravel 在 phpword 中绘制表格 下面的代码是在 doc 文件中编写内容的示例。

        $wordTest = new \PhpOffice\PhpWord\PhpWord();

    $newSection = $wordTest->addSection();

    $desc1 = "The Portfolio details is a very useful feature of the web page. You can establish your archived details and the works to the entire web community. It was outlined to bring in extra clients, get you selected based on this details.";

    $newSection->addText($desc1, array('name' => 'Tahoma', 'size' => 15, 'color' => 'red'));

    $objectWriter = \PhpOffice\PhpWord\IOFactory::createWriter($wordTest, 'Word2007');

    $objectWriter->save(storage_path('TestWordFile.docx'));

请举个例子说明我如何在那里画桌子

【问题讨论】:

  • 尝试使用addHTML函数并传递完整的HTML,reference
  • 但它的风格不起作用
  • style 对于此类文件写入无法正常工作,因为 word 无法理解 CSS。尝试使用内联 CSS,看看是否可行。

标签: laravel phpword phpoffice


【解决方案1】:

绘制表格我通常使用此代码

$table = array('borderColor'=>'black', 'borderSize'=> 1, 'cellMargin'=>50, 'valign'=>'center');
        $phpWord->addTableStyle('table', $table);
        $table = $section->addTable('table');
        $table->addRow();
        $table->addCell(1750)->addText(htmlspecialchars("#"),$bold);
        $table->addCell(1750)->addText(htmlspecialchars("Attendance Date "),$bold);

【讨论】:

    猜你喜欢
    • 2021-11-01
    • 1970-01-01
    • 2020-05-18
    • 2021-01-24
    • 2016-05-27
    • 2014-07-19
    • 2016-02-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多