本文整理汇总了PHP中PhpOffice\PhpWord\Shared\XMLWriter::writeElement方法的典型用法代码示例。如果您正苦于以下问题:PHP XMLWriter::writeElement方法的具体用法?PHP XMLWriter::writeElement怎么用?PHP XMLWriter::writeElement使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PhpOffice\PhpWord\Shared\XMLWriter
的用法示例。
在下文中一共展示了XMLWriter::writeElement方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: writeSetting
/**
* Write indivual setting, recursive to any child settings
*
* @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param string $settingKey
* @param array|string $settingValue
*/
protected function writeSetting($xmlWriter, $settingKey, $settingValue)
{
if ($settingValue == '') {
$xmlWriter->writeElement($settingKey);
} else {
$xmlWriter->startElement($settingKey);
foreach ($settingValue as $childKey => $childValue) {
if ($childKey == '@attributes') {
foreach ($childValue as $key => $val) {
$xmlWriter->writeAttribute($key, $val);
}
} else {
$this->writeSetting($xmlWriter, $childKey, $childValue);
}
}
$xmlWriter->endElement();
}
}
示例2: writeDefaultStyles
/**
* Write default font and other default styles
*
* @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param array $styles
*/
private function writeDefaultStyles(XMLWriter $xmlWriter, PhpWord $phpWord, $styles)
{
$fontName = $phpWord->getDefaultFontName();
$fontSize = $phpWord->getDefaultFontSize();
// Default font
$xmlWriter->startElement('w:docDefaults');
$xmlWriter->startElement('w:rPrDefault');
$xmlWriter->startElement('w:rPr');
$xmlWriter->startElement('w:rFonts');
$xmlWriter->writeAttribute('w:ascii', $fontName);
$xmlWriter->writeAttribute('w:hAnsi', $fontName);
$xmlWriter->writeAttribute('w:eastAsia', $fontName);
$xmlWriter->writeAttribute('w:cs', $fontName);
$xmlWriter->endElement();
// w:rFonts
$xmlWriter->startElement('w:sz');
$xmlWriter->writeAttribute('w:val', $fontSize * 2);
$xmlWriter->endElement();
// w:sz
$xmlWriter->startElement('w:szCs');
$xmlWriter->writeAttribute('w:val', $fontSize * 2);
$xmlWriter->endElement();
// w:szCs
$xmlWriter->endElement();
// w:rPr
$xmlWriter->endElement();
// w:rPrDefault
$xmlWriter->endElement();
// w:docDefaults
// Normal style
$xmlWriter->startElement('w:style');
$xmlWriter->writeAttribute('w:type', 'paragraph');
$xmlWriter->writeAttribute('w:default', '1');
$xmlWriter->writeAttribute('w:styleId', 'Normal');
$xmlWriter->startElement('w:name');
$xmlWriter->writeAttribute('w:val', 'Normal');
$xmlWriter->endElement();
// w:name
if (array_key_exists('Normal', $styles)) {
$styleWriter = new ParagraphStyleWriter($xmlWriter, $styles['Normal']);
$styleWriter->write();
}
$xmlWriter->endElement();
// w:style
// FootnoteReference style
if (!array_key_exists('FootnoteReference', $styles)) {
$xmlWriter->startElement('w:style');
$xmlWriter->writeAttribute('w:type', 'character');
$xmlWriter->writeAttribute('w:styleId', 'FootnoteReference');
$xmlWriter->startElement('w:name');
$xmlWriter->writeAttribute('w:val', 'Footnote Reference');
$xmlWriter->endElement();
// w:name
$xmlWriter->writeElement('w:semiHidden');
$xmlWriter->writeElement('w:unhideWhenUsed');
$xmlWriter->startElement('w:rPr');
$xmlWriter->startElement('w:vertAlign');
$xmlWriter->writeAttribute('w:val', 'superscript');
$xmlWriter->endElement();
// w:vertAlign
$xmlWriter->endElement();
// w:rPr
$xmlWriter->endElement();
// w:style
}
}
示例3: writeNote
/**
* Write note item
*
* @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param \PhpOffice\PhpWord\Element\Footnote|\PhpOffice\PhpWord\Element\Endnote $element
*/
protected function writeNote(XMLWriter $xmlWriter, $element)
{
$xmlWriter->startElement($this->elementNode);
$xmlWriter->writeAttribute('w:id', $element->getRelationId());
$xmlWriter->startElement('w:p');
// Paragraph style
$styleWriter = new ParagraphStyleWriter($xmlWriter, $element->getParagraphStyle());
$styleWriter->setIsInline(true);
$styleWriter->write();
// Reference symbol
$xmlWriter->startElement('w:r');
$xmlWriter->startElement('w:rPr');
$xmlWriter->startElement('w:rStyle');
$xmlWriter->writeAttribute('w:val', $this->refStyle);
$xmlWriter->endElement();
// w:rStyle
$xmlWriter->endElement();
// w:rPr
$xmlWriter->writeElement($this->refNode);
$xmlWriter->endElement();
// w:r
// Empty space after refence symbol
$xmlWriter->startElement('w:r');
$xmlWriter->startElement('w:t');
$xmlWriter->writeAttribute('xml:space', 'preserve');
$xmlWriter->writeRaw(' ');
$xmlWriter->endElement();
// w:t
$xmlWriter->endElement();
// w:r
$this->writeContainerElements($xmlWriter, $element);
$xmlWriter->endElement();
// w:p
$xmlWriter->endElement();
// $this->elementNode
}
示例4: writeShape
/**
* Write shape
*
* @link http://www.datypic.com/sc/ooxml/t-a_CT_ShapeProperties.html
* @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param bool $line
* @return void
*/
private function writeShape(XMLWriter $xmlWriter, $line = false)
{
$xmlWriter->startElement('c:spPr');
$xmlWriter->startElement('a:ln');
if ($line === true) {
$xmlWriter->writeElement('a:solidFill');
} else {
$xmlWriter->writeElement('a:noFill');
}
$xmlWriter->endElement();
// a:ln
$xmlWriter->endElement();
// c:spPr
}