本文整理汇总了PHP中PhpOffice\PhpWord\Shared\XMLWriter::writeElementIf方法的典型用法代码示例。如果您正苦于以下问题:PHP XMLWriter::writeElementIf方法的具体用法?PHP XMLWriter::writeElementIf怎么用?PHP XMLWriter::writeElementIf使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PhpOffice\PhpWord\Shared\XMLWriter
的用法示例。
在下文中一共展示了XMLWriter::writeElementIf方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: writeParagraphStyle
/**
* Write paragraph style
*
* @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param string $styleName
* @param \PhpOffice\PhpWord\Style\Paragraph $style
*/
private function writeParagraphStyle(XMLWriter $xmlWriter, $styleName, ParagraphStyle $style)
{
$xmlWriter->startElement('w:style');
$xmlWriter->writeAttribute('w:type', 'paragraph');
$xmlWriter->writeAttribute('w:customStyle', '1');
$xmlWriter->writeAttribute('w:styleId', $styleName);
$xmlWriter->startElement('w:name');
$xmlWriter->writeAttribute('w:val', $styleName);
$xmlWriter->endElement();
// Parent style
$basedOn = $style->getBasedOn();
$xmlWriter->writeElementIf(!is_null($basedOn), 'w:basedOn', 'w:val', $basedOn);
// Next paragraph style
$next = $style->getNext();
$xmlWriter->writeElementIf(!is_null($next), 'w:next', 'w:val', $next);
// w:pPr
$styleWriter = new ParagraphStyleWriter($xmlWriter, $style);
$styleWriter->write();
$xmlWriter->endElement();
}