如何改变PHPWord表格单元格的高度?

时间:2022-11-21 21:02:43

When im creating a simple table with PHPTable the rows seems to be a bit too height. I would like them to be the same heights as the font, and with no padding/spacing below or above the text in the cells.. but can't get it to work without any "padding"...

当我用PHPTable创建一个简单的表时,行看起来有点高。我希望它们的高度与字体相同,并且单元格中没有空格或空格。但如果没有任何“填充”,它就无法工作。

Code:

代码:

$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']);
}

1 个解决方案

#1


7  

Found the answer. Had to add paragraph style on each element 'spaceAfter' => 0. See working code below:

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

// 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);
}

This helped me. Hopes it helps you as well.

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

#1


7  

Found the answer. Had to add paragraph style on each element 'spaceAfter' => 0. See working code below:

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

// 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);
}

This helped me. Hopes it helps you as well.

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