2013-10-08 380 views
4

當我用PHPTable創建一個簡單的表時,這些行似乎有點太高。 我希望它們與字體的高度相同,並且在單元格中文本的下方或上方沒有填充/間距..但不能在沒有任何「填充」的情況下使其工作...如何更改PHPWord表格單元格高度?

代碼:

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

回答

7

找到了答案。只好每個元素添加段落樣式「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); 
} 

這幫助了我。希望它可以幫助你。

+0

非常感謝!我一直試圖使用「間距」=> 0,甚至沒有想過嘗試'spaceAfter'=> 0。 –

相關問題