如何更改 PHP 表格单元格高度


How to change PHPWord table cell height?

当我使用 PHPTable 创建一个简单的表时,行似乎有点太高了。我希望它们与字体的高度相同,并且在单元格中的文本下方或上方没有填充/间距。但是在没有任何"填充"的情况下无法让它工作......

法典:

$styleTable = array('borderSize'=>0, 
                    'borderColor'=>'eeeeee',
                    'cellMargin'=>0, 
                    'spaceBefore' => 0, 
                    'spaceAfter' => 0,
                    'spacing' => 0);
$PHPWord->addTableStyle('myOwnTableStyle', $styleTable);
$table = $section->addTable('myOwnTableStyle');
foreach($aryData['json_data'] as $data) {
  $table->addRow();
  $table->addCell(4000)->addText($data['label'] . ':', array('bold'=>true));
  $table->addCell(8000)->addText($data['value']);
}

找到了答案。必须在每个元素"spaceAfter"=> 0上添加段落样式。请参阅下面的工作代码:

// New Word Document
$PHPWord = new PHPWord();
// This is used to remove "padding" below text-lines
$noSpace = array('spaceAfter' => 0);
$section = $PHPWord->createSection();
$table = $section->addTable();
foreach($aryData['json_data'] as $data) {
  $table->addRow();
  $table->addCell(4000)->addText($data['label'] . ':', array('bold'=>true), $noSpace);
  $table->addCell(8000)->addText($data['value'], array(), $noSpace);
}

这对我有帮助。希望它也能帮助你。