How to change cell height of a PHPWord table?

When I create a simple table with PHPTable, the rows seem a little too high. I would like them to be the same height as the font, and without spaces / intervals below or above the text in the cells .. but cannot make it work without any "indentation" ...

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']);
}
+4
source share
1 answer

Found the answer. You must add a paragraph style for each element of "spaceAfter" => 0. See working code below:

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

It helps me. Hope this helps you.

+7
source

All Articles