4

当我用 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']);
}
4

1 回答 1

11

找到了答案。必须在每个元素 '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);
}

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

于 2013-10-08T12:55:37.777 回答