首页 > 解决方案 > 创建表 - phpword

问题描述

我正在尝试用 phpword 创建一个表。但是我正在努力解决这个表的配置语法。

下面是我的代码:

    // Define table style arrays
    $styleTable = array('borderSize'=>2, 'cellMargin'=>10);
    $styleFirstRow = array('borderBottomSize'=>5, 'bgColor'=>'#D3D3D3');
    // Define cell style arrays
    $styleCell = array('valign'=>'center', 'bgColor'=>'#D3D3D3');
    $styleCellBTLR = array('valign'=>'center');
    // Define font style for first row
    $fontStyle = array('bold'=>true, 'align'=>'center');


    // Add table style
    $wordTest->addTableStyle('CoverLine', $styleTable, $styleFirstRow);
    // Add table
    $table = $newSection->addTable('CoverLine');
    // Add row
   // $table->addRow(200);
    // Add cells
   // $table->addCell(10000, $styleCell)->addText('Employer Details ', $fontStyle);
    //$table->addCell(1800)->addText($curriculum->curriculum_code);

    $table->addRow(500);
    $table->addCell(2200, $styleCell)->addText(' Code', $fontStyle);
    $table->addCell(5000, $styleCell)->addText(' Title', $fontStyle);

    $table->addRow(500);
    $table->addCell(2200)->addText('', $fontStyle);
    $table->addCell(5000)->addText('', $fontStyle);
    $table->addRow(500);
    $table->addCell(2200, $styleCell)->addText('', $fontStyle);
    $table->addCell(1200, $styleCell)->addText(' Name', $fontStyle);
    $table->addCell(2500, $styleCell)->addText(' Email', $fontStyle);
    $table->addCell(2000, $styleCell)->addText(' Phone', $fontStyle);
    $table->addCell(2000, $styleCell)->addText(' Logo', $fontStyle);
    $table->addRow(600);
    $table->addCell(700, $styleCell)->addText(' Development Quality Partner', $fontStyle);
    $table->addCell(2000)->addText('');
    $table->addCell(2000)->addText('');
    $table->addCell(2000)->addText('');
    $table->addCell(2000)->addText('');

下图显示了我想要实现的目标: 在此处输入图像描述

我得到的与刺激太大不同。请协助。我已经浏览了 phpword 文档,似乎我遗漏了一些东西。

标签: phplaravelphpword

解决方案


表格网格不适用于仅使用单元格宽度来实现跨越多列或多行的单元格;需要明确定义跨越多列和多行的单元格。

您可以在How to make the table in word using PHPWord 中找到另一个类似的问题和答案示例,其中包括多个行跨度和列跨度?


推荐阅读