我有一个表格单元格,我想放置几个列表项目。以下是我的代码。
基本上,我定义了一大堆样式,然后添加行和单元格。在其中一个单元格中,我添加了一个无序列表。
注意:如果您想知道为什么我在这里有“确切”参数,$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
段落样式应用到表格单元格中的列表项目但没有运气。
有谁知道这样的事情是如何实现的?
答案 0 :(得分:2)
在Cell.php中进行更改。
替换:
public function addListItem($text, $depth = 0, $styleText = null, $styleList = null) {
$text = utf8_encode($text);
$listItem = new PHPWord_Section_ListItem($text, $depth, $styleText, $styleList, $styleParagraph);
$this->_elementCollection[] = $listItem;
return $listItem;
}
通过:
public function addListItem($text, $depth = 0, $styleText = null, $styleList = null, $styleParagraph = null) {
$text = utf8_encode($text);
$listItem = new PHPWord_Section_ListItem($text, $depth, $styleText, $styleList, $styleParagraph);
$this->_elementCollection[] = $listItem;
return $listItem;
}
像我一样的魅力!