Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change PHPWord table cell height?

Tags:

html

php

phpword

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"...

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']);
}
like image 821
Vidar Vestnes Avatar asked Dec 20 '22 23:12

Vidar Vestnes


1 Answers

Found the answer. Had to add paragraph style on each element '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);
}

This helped me. Hopes it helps you as well.

like image 113
Vidar Vestnes Avatar answered Jan 02 '23 21:01

Vidar Vestnes