PhpWord表没有边框

时间:2018-06-06 19:44:30

标签: php phpword

我在phpword文件中添加了一个表,但似乎无法更改表的边框。我读到borderSize是一个特定于细胞的设置,但即使没有变化。边界根本没有变化。我已经尝试了很多关于堆栈溢出的事情,但似乎无法找到解决方案。有没有人遇到过类似的问题?

$phpWord = \PhpOffice\PhpWord\IOFactory::load($file);
$styleTable = array('borderColor'=>'#CCC', 'borderSize'=> 2, 'cellMargin'=>50, 'valign'=>'center');
$styleFirstRow = array('bgColor'=>'#CCC', 'bold'=>true, 'size'=>11, 'valign'=>'center');
$styleCell = array('valign'=>'center');
$fontStyle = array('bold'=>false, 'align'=>'center', 'color'=>'ccc');

$phpWord->addTableStyle('myTable', $styleTable, $styleFirstRow);

$section = $phpWord->createSection();
$table = $section->addTable('myTable');

$table->addRow(900);
$table->addCell(2000, $styleCell)->addText('#SIG01_100_200#', $fontStyle);
$table->addCell(2000, $styleCell)->addText('#SIG02_100_200#', $fontStyle);

$xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord , 'PDF');
$xmlWriter->save($file_pdf);

1 个答案:

答案 0 :(得分:0)

设置每个单元格每一侧的边框颜色和边框大小:

$styleCell =
[
    'borderColor' =>'ff0000',
    'borderSize' => 6,
];
$table->addCell(2000, $styleCell);

$styleCell =
[
    'borderTopColor' =>'ff0000',
    'borderTopSize' => 6,
    'borderRightColor' =>'ff0000',
    'borderRightSize' => 6,
    'borderBottomColor' =>'ff0000',
    'borderBottomSize' => 6,
    'borderLeftColor' =>'ff0000',
    'borderLeftSize' => 6,
];
$table->addCell(2000, $styleCell);