本文整理汇总了PHP中PhpOffice\PhpWord\Shared\XMLWriter::writeAttribute方法的典型用法代码示例。如果您正苦于以下问题:PHP XMLWriter::writeAttribute方法的具体用法?PHP XMLWriter::writeAttribute怎么用?PHP XMLWriter::writeAttribute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PhpOffice\PhpWord\Shared\XMLWriter
的用法示例。
在下文中一共展示了XMLWriter::writeAttribute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: writeFontFaces
/**
* Write font faces declaration
*/
protected function writeFontFaces(XMLWriter $xmlWriter)
{
$xmlWriter->startElement('office:font-face-decls');
$arrFonts = array();
$styles = Style::getStyles();
$numFonts = 0;
if (count($styles) > 0) {
foreach ($styles as $style) {
// Font
if ($style instanceof Font) {
$numFonts++;
$name = $style->getName();
if (!in_array($name, $arrFonts)) {
$arrFonts[] = $name;
// style:font-face
$xmlWriter->startElement('style:font-face');
$xmlWriter->writeAttribute('style:name', $name);
$xmlWriter->writeAttribute('svg:font-family', $name);
$xmlWriter->endElement();
}
}
}
}
if (!in_array(PhpWord::DEFAULT_FONT_NAME, $arrFonts)) {
$xmlWriter->startElement('style:font-face');
$xmlWriter->writeAttribute('style:name', PhpWord::DEFAULT_FONT_NAME);
$xmlWriter->writeAttribute('svg:font-family', PhpWord::DEFAULT_FONT_NAME);
$xmlWriter->endElement();
}
$xmlWriter->endElement();
}
示例2: writeContentType
/**
* Write content types element
*
* @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter XML Writer
* @param array $parts
* @param boolean $isDefault
*/
private function writeContentType(XMLWriter $xmlWriter, $parts, $isDefault)
{
foreach ($parts as $partName => $contentType) {
$partType = $isDefault ? 'Default' : 'Override';
$partAttribute = $isDefault ? 'Extension' : 'PartName';
$xmlWriter->startElement($partType);
$xmlWriter->writeAttribute($partAttribute, $partName);
$xmlWriter->writeAttribute('ContentType', $contentType);
$xmlWriter->endElement();
}
}
示例3: writeContentType
/**
* Write content types element
*
* @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter XML Writer
* @param array $parts
* @param boolean $isDefault
* @throws \PhpOffice\PhpWord\Exception\Exception
*/
private function writeContentType(XMLWriter $xmlWriter, $parts, $isDefault)
{
foreach ($parts as $partName => $contentType) {
if ($partName != '' && $contentType != '') {
$partType = $isDefault ? 'Default' : 'Override';
$partAttribute = $isDefault ? 'Extension' : 'PartName';
$xmlWriter->startElement($partType);
$xmlWriter->writeAttribute($partAttribute, $partName);
$xmlWriter->writeAttribute('ContentType', $contentType);
$xmlWriter->endElement();
} else {
throw new Exception("Invalid parameters passed.");
}
}
}
示例4: writeFontFaces
/**
* Write font faces declaration
*/
protected function writeFontFaces(XMLWriter $xmlWriter)
{
$xmlWriter->startElement('office:font-face-decls');
$fontTable = array();
$styles = Style::getStyles();
$numFonts = 0;
if (count($styles) > 0) {
foreach ($styles as $style) {
// Font
if ($style instanceof Font) {
$numFonts++;
$name = $style->getName();
if (!in_array($name, $fontTable)) {
$fontTable[] = $name;
// style:font-face
$xmlWriter->startElement('style:font-face');
$xmlWriter->writeAttribute('style:name', $name);
$xmlWriter->writeAttribute('svg:font-family', $name);
$xmlWriter->endElement();
}
}
}
}
if (!in_array(Settings::getDefaultFontName(), $fontTable)) {
$xmlWriter->startElement('style:font-face');
$xmlWriter->writeAttribute('style:name', Settings::getDefaultFontName());
$xmlWriter->writeAttribute('svg:font-family', Settings::getDefaultFontName());
$xmlWriter->endElement();
}
$xmlWriter->endElement();
}
示例5: writeSide
/**
* Write side.
*
* @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param string $side
* @param int $width
* @param string $color
* @return void
*/
private function writeSide(XMLWriter $xmlWriter, $side, $width, $color = null)
{
$xmlWriter->startElement('w:' . $side);
if (!empty($this->colors)) {
if ($color === null && !empty($this->attributes)) {
if (isset($this->attributes['defaultColor'])) {
$color = $this->attributes['defaultColor'];
}
}
$xmlWriter->writeAttribute('w:val', 'single');
$xmlWriter->writeAttribute('w:sz', $width);
$xmlWriter->writeAttribute('w:color', $color);
if (!empty($this->attributes)) {
if (isset($this->attributes['space'])) {
$xmlWriter->writeAttribute('w:space', $this->attributes['space']);
}
}
} else {
$xmlWriter->writeAttribute('w:w', $width);
$xmlWriter->writeAttribute('w:type', 'dxa');
}
$xmlWriter->endElement();
}
示例6: 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();
}
}
示例7: 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
}
}
示例8: writeSectionSettings
/**
* Write end section.
*
* @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param \PhpOffice\PhpWord\Element\Section $section
* @return void
*/
private function writeSectionSettings(XMLWriter $xmlWriter, Section $section)
{
$xmlWriter->startElement('w:sectPr');
// Header reference
foreach ($section->getHeaders() as $header) {
$rId = $header->getRelationId();
$xmlWriter->startElement('w:headerReference');
$xmlWriter->writeAttribute('w:type', $header->getType());
$xmlWriter->writeAttribute('r:id', 'rId' . $rId);
$xmlWriter->endElement();
}
// Footer reference
foreach ($section->getFooters() as $footer) {
$rId = $footer->getRelationId();
$xmlWriter->startElement('w:footerReference');
$xmlWriter->writeAttribute('w:type', $footer->getType());
$xmlWriter->writeAttribute('r:id', 'rId' . $rId);
$xmlWriter->endElement();
}
// Different first page
if ($section->hasDifferentFirstPage()) {
$xmlWriter->startElement('w:titlePg');
$xmlWriter->endElement();
}
// Section settings
$styleWriter = new SectionStyleWriter($xmlWriter, $section->getStyle());
$styleWriter->write();
$xmlWriter->endElement();
// w:sectPr
}
示例9: writeCustomProperty
/**
* Write individual property
*
* @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param string $property
* @param string $value
* @return void
*
* @todo Handle other `$type`: double|date|dateTime|duration|boolean (4th arguments)
*/
private function writeCustomProperty(XMLWriter $xmlWriter, $property, $value)
{
$xmlWriter->startElement('meta:user-defined');
$xmlWriter->writeAttribute('meta:name', $property);
// if ($type !== null) {
// $xmlWriter->writeAttribute('meta:value-type', $type);
// }
$xmlWriter->writeRaw($value);
$xmlWriter->endElement();
// meta:user-defined
}
示例10: 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
}
示例11: writeWatermark
/**
* Write watermark element
*/
private function writeWatermark(XMLWriter $xmlWriter, ImageElement $element)
{
$rId = $element->getRelationId();
$style = $element->getStyle();
$style->setPositioning('absolute');
$styleWriter = new ImageStyleWriter($xmlWriter, $style);
$xmlWriter->startElement('w:p');
$xmlWriter->startElement('w:r');
$xmlWriter->startElement('w:pict');
$xmlWriter->startElement('v:shape');
$xmlWriter->writeAttribute('type', '#_x0000_t75');
$styleWriter->write();
$xmlWriter->startElement('v:imagedata');
$xmlWriter->writeAttribute('r:id', 'rId' . $rId);
$xmlWriter->writeAttribute('o:title', '');
$xmlWriter->endElement();
// v:imagedata
$xmlWriter->endElement();
// v:shape
$xmlWriter->endElement();
// w:pict
$xmlWriter->endElement();
// w:r
$xmlWriter->endElement();
// w:p
}
示例12: writeSeriesItem
/**
* Write series items.
*
* @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param string $type
* @param array $values
* @return void
*/
private function writeSeriesItem(XMLWriter $xmlWriter, $type, $values)
{
$types = array('cat' => array('c:cat', 'c:strLit'), 'val' => array('c:val', 'c:numLit'), 'xVal' => array('c:xVal', 'c:strLit'), 'yVal' => array('c:yVal', 'c:numLit'));
list($itemType, $itemLit) = $types[$type];
$xmlWriter->startElement($itemType);
$xmlWriter->startElement($itemLit);
$index = 0;
foreach ($values as $value) {
$xmlWriter->startElement('c:pt');
$xmlWriter->writeAttribute('idx', $index);
$xmlWriter->startElement('c:v');
$xmlWriter->writeRaw($value);
$xmlWriter->endElement();
// c:v
$xmlWriter->endElement();
// c:pt
$index++;
}
$xmlWriter->endElement();
// $itemLit
$xmlWriter->endElement();
// $itemType
}
示例13: writeParagraph
/**
* Write level paragraph.
*
* @since 0.11.0
*
* @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param \PhpOffice\PhpWord\Style\NumberingLevel $level
* @return void
* @todo Use paragraph style writer
*/
private function writeParagraph(XMLWriter $xmlWriter, NumberingLevel $level)
{
$tabPos = $level->getTabPos();
$left = $level->getLeft();
$hanging = $level->getHanging();
$xmlWriter->startElement('w:pPr');
$xmlWriter->startElement('w:tabs');
$xmlWriter->startElement('w:tab');
$xmlWriter->writeAttribute('w:val', 'num');
$xmlWriter->writeAttributeIf($tabPos !== null, 'w:pos', $tabPos);
$xmlWriter->endElement();
// w:tab
$xmlWriter->endElement();
// w:tabs
$xmlWriter->startElement('w:ind');
$xmlWriter->writeAttributeIf($left !== null, 'w:left', $left);
$xmlWriter->writeAttributeIf($hanging !== null, 'w:hanging', $hanging);
$xmlWriter->endElement();
// w:ind
$xmlWriter->endElement();
// w:pPr
}
示例14: writeTableStyle
/**
* Write table style
*
* @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param string $styleName
* @param \PhpOffice\PhpWord\Style\Table $style
*/
private function writeTableStyle(XMLWriter $xmlWriter, $styleName, TableStyle $style)
{
$xmlWriter->startElement('w:style');
$xmlWriter->writeAttribute('w:type', 'table');
$xmlWriter->writeAttribute('w:customStyle', '1');
$xmlWriter->writeAttribute('w:styleId', $styleName);
$xmlWriter->startElement('w:name');
$xmlWriter->writeAttribute('w:val', $styleName);
$xmlWriter->endElement();
$xmlWriter->startElement('w:uiPriority');
$xmlWriter->writeAttribute('w:val', '99');
$xmlWriter->endElement();
$styleWriter = new TableStyleWriter($xmlWriter, $style);
$styleWriter->write();
$xmlWriter->endElement();
// w:style
}
示例15: writeRel
/**
* Write individual rels entry.
*
* Format:
* <Relationship Id="rId..." Type="http://..." Target="....xml" TargetMode="..." />
*
* @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param int $relId Relationship ID
* @param string $type Relationship type
* @param string $target Relationship target
* @param string $targetMode Relationship target mode
* @return void
* @throws \PhpOffice\PhpWord\Exception\Exception
*/
private function writeRel(XMLWriter $xmlWriter, $relId, $type, $target, $targetMode = '')
{
if ($type != '' && $target != '') {
if (strpos($relId, 'rId') === false) {
$relId = 'rId' . $relId;
}
$xmlWriter->startElement('Relationship');
$xmlWriter->writeAttribute('Id', $relId);
$xmlWriter->writeAttribute('Type', 'http://schemas.openxmlformats.org/' . $type);
$xmlWriter->writeAttribute('Target', $target);
if ($targetMode != '') {
$xmlWriter->writeAttribute('TargetMode', $targetMode);
}
$xmlWriter->endElement();
} else {
throw new Exception("Invalid parameters passed.");
}
}