本文整理匯總了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
}