【发布时间】:2013-12-17 17:26:24
【问题描述】:
我有一个表格单元格,我想在其中放置一些列表项。下面是我的代码。
基本上,我定义了一大堆样式,然后添加行和单元格。在其中一个单元格中,我添加了一个无序列表。
注意:如果您想知道为什么我在这里有“精确”参数,$table->addRow(250, "exact"); 这是因为我使用了this fix for controlling table row height。
// Table
$styleTable = array( 'borderSize' => 7,
'cellMarginTop' => 0,
'cellMarginLeft' => 100,
'valign' => 'center',
'spaceAfter' => 0
);
$styleCell = array( 'spaceAfter' => 0
);
$cellTextStyle = array( 'bold' => false,
'size' => 10,
'name' => 'Calibri'
);
$cellTextStyleBold = array( 'bold' => true,
'size' => 10,
'name' => 'Calibri'
);
$listStyleText = array( 'spaceAfter' => 0,
'spaceBefore' => 0,
'spacing' => 0,
'size' => 10
);
$listStyle = array( 'spaceAfter' => 0,
'spaceBefore' => 0,
'spacing' => 0
);
$listStyleParagraph = array( 'spaceAfter' => 0,
'spaceBefore' => 0,
'spacing' => 0
);
$PHPWord->addTableStyle('myTable', $styleTable);
$table = $section->addTable('myTable');
$table->addRow(250, "exact");
$table->addCell(5760, $styleCell)->addText('Type:', $cellTextStyleBold);
$table->addCell(5760, $styleCell)->addText('Kazvin', $cellTextStyle);
$table->addRow(250, "null");
$table->addCell(5760, $styleCell)->addText('Description:', $cellTextStyleBold);
$cell = $table->addCell(5760, $styleCell);
// Add listitem elements inside table cell
$PHPWord->addParagraphStyle('listStyle', array('spaceAfter'=>0));
$cell->addListItem('100% wool pile on a cotton foundation', 0, null, null, 'listStyle');
$cell->addListItem('Semi-open ivory field', 0, null, null, 'listStyle');
$cell->addListItem('Coral and powder blue floral medallion', 0, null, null, 'listStyle');
$cell->addListItem('Formal coral, powder blue and ivory border', 0, null, null, 'listStyle');
问题是列表项段落样式在执行$cell->addListItem....之类的操作时没有被使用
如果我使用$section-> 而不是$cell->
// Add listitem elements inside table cell
$PHPWord->addParagraphStyle('listStyle', array('spaceAfter'=>0));
$section->addListItem('100% wool pile on a cotton foundation', 0, null, null, 'listStyle');
$section->addListItem('Semi-open ivory field', 0, null, null, 'listStyle');
$section->addListItem('Coral and powder blue floral medallion', 0, null, null, 'listStyle');
$section->addListItem('Formal coral, powder blue and ivory border', 0, null, null, 'listStyle');
然后'spaceAfter' => 0 工作正常。但是,无序列表出现在表格单元格之外。
我已经尝试了好几天,试图找到一种方法将'spaceAfter' => 0 段落样式应用于表格单元格内的列表项,但没有成功。
有谁知道这样的事情是如何实现的?
【问题讨论】: