如何删除PhpWord表格中的边框?

How to remove border in PhpWord table?

提问人:Premlatha 提问时间:11/10/2023 更新时间:11/10/2023 访问量:22

问:

我使用phpword创建表。我只想为特定单元格设置边框。为了测试,我创建了两个数组样式和.我将 style1 设置为单元格 1,将 style2 设置为单元格 2。在生成的Word文件中,两个单元格都有边框。border=6border=0

<?php
 include_once '../vendor/autoload.php';
use PhpOffice\PhpWord\Element\Table;
use PhpOffice\PhpWord\TemplateProcessor;
use PhpOffice\PhpWord\ComplexType\TblWidth;

$styleCell1 = array('borderColor' =>'black', 'borderSize' => 6)
$styleCell2 = array('borderColor' =>'black', 'borderSize' => 0);
$table = new Table();

    $table->addRow();
    $table->addCell(700,$styleCell1)->addText('cell 1');
    $table->addCell(500,$styleCell2)->addText(cell 2);
 $phpWord = new TemplateProcessor('phpWordTableTemplate.docx');
 $phpWord->setComplexBlock('{table}', $table);
 $phpWord->saveAs('template_with_table_output.docx');
 ?>

如何删除PhpWord表格中的边框?

php 边框 phpword

评论


答:

0赞 Premlatha 11/10/2023 #1

只能将边框 none 设置为表格单元格:

use PhpOffice\PhpWord\SimpleType\Border;
$styleCell2 = array('borderColor'=>'black', 'borderSize'=> 0,  'borderStyle' => Border::NONE);