我正在使用PHPWord创建word文件。我想用段落样式创建列表。为此,我遵循PHPWord代码标准。
我创建精选列表的代码: -
$listItemRun = $section->addListItemRun();
foreach($li['li'] as $element){
if(isset($element['strong']) && !empty($element['strong'])){
$listItemRun->addText($this->trimString($element['strong']), array('format' => 'decimal','lineHeight' => 1,'bold'=>true),array('spaceAfter'=>0,'lineHeight'=>1));
}
if(isset($element['b']) && !empty($element['b'])){
$listItemRun->addText($this->trimString($element['b']).' ', array('format' => 'decimal','bold'=>true),array('spaceAfter'=>0,'lineHeight'=>1));
}
if(isset($element['#text'][0]) && !empty($element['#text'][0])){
$listItemRun->addText($this->trimString($element['#text'][0]).' ',array('format' => 'decimal'),array('spaceAfter'=>0,'lineHeight'=>1));
}
if(isset($element['u']) && !empty($element['u'])){
$listItemRun->addText($this->trimString($element['u']).' ', array('underline' => \PhpOffice\PhpWord\Style\Font::UNDERLINE_SINGLE),array('spaceAfter'=>0,'lineHeight'=>1));
}
if(isset($element['em']) && !empty($element['em'])){
$listItemRun->addText($this->trimString($element['em']).' ', array('italic' => true),array('spaceAfter'=>0,'lineHeight'=>1));
}
}
我遵循以下PHPWord代码:
$listItemRun = $section->addListItemRun();
$listItemRun->addText('List item 1');
$listItemRun->addText(' in bold', array('bold'=>true));
$listItemRun = $section->addListItemRun();
$listItemRun->addText('List item 2');
$listItemRun->addText(' in italic', array('italic'=>true));
$listItemRun = $section->addListItemRun();
$listItemRun->addText('List item 3');
$listItemRun->addText(' underlined', array('underline'=>'dash'));
除了线条和间距外,每件东西都在工作。 列表行高度为1.15,我想给行高1,也想删除列表项中的间距。
答案 0 :(得分:2)
我们可以通过列表项中的代码来给出间距和行高: -
$phpWord->addParagraphStyle('P-listStyle', array('spaceAfter'=>0,'lineHeight'=>1.0));
$listItemRun = $section->addListItemRun(0,null, 'P-listStyle');
$listItemRun->addText('List item 1');
$listItemRun->addText(' in bold', array('bold'=>true));
$listItemRun = $section->addListItemRun();
$listItemRun->addText('List item 2');
$listItemRun->addText(' in italic', array('italic'=>true));
$listItemRun = $section->addListItemRun();
$listItemRun->addText('List item 3');
$listItemRun->addText(' underlined', array('underline'=>'dash'));