本文整理汇总了PHP中PhpOffice\PhpWord\Shared\XMLWriter::startElement方法的典型用法代码示例。如果您正苦于以下问题:PHP XMLWriter::startElement方法的具体用法?PHP XMLWriter::startElement怎么用?PHP XMLWriter::startElement使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PhpOffice\PhpWord\Shared\XMLWriter
的用法示例。
在下文中一共展示了XMLWriter::startElement方法的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: 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();
}
示例3: startElementP
/**
* Start w:p DOM element.
*
* @uses \PhpOffice\PhpWord\Writer\Word2007\Element\PageBreak::write()
* @return void
*/
protected function startElementP()
{
if (!$this->withoutP) {
$this->xmlWriter->startElement('w:p');
// Paragraph style
if (method_exists($this->element, 'getParagraphStyle')) {
$this->writeParagraphStyle();
}
}
}
示例4: 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();
}
}
示例5: 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.");
}
}
}
示例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: 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();
}
示例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: writeDropDown
/**
* Write dropdown.
*
* @link http://www.datypic.com/sc/ooxml/t-w_CT_FFDDList.html
* @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param \PhpOffice\PhpWord\Element\FormField $element
* @return void
*/
private function writeDropDown(XMLWriter $xmlWriter, FormFieldElement $element)
{
$default = $element->getDefault();
$value = $element->getValue();
if ($value == null) {
$value = $default;
}
$entries = $element->getEntries();
$xmlWriter->startElement('w:ddList');
$xmlWriter->writeElementBlock('w:result', 'w:val', $value);
$xmlWriter->writeElementBlock('w:default', 'w:val', $default);
foreach ($entries as $entry) {
$xmlWriter->writeElementBlock('w:listEntry', 'w:val', $entry);
}
$xmlWriter->endElement();
}
示例11: writeDate
/**
* Write date.
*
* @link http://www.datypic.com/sc/ooxml/t-w_CT_SdtDate.html
* @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param \PhpOffice\PhpWord\Element\SDT $element
* @return void
*/
private function writeDate(XMLWriter $xmlWriter, SDTElement $element)
{
$type = $element->getType();
$xmlWriter->startElement("w:{$type}");
$xmlWriter->writeElementBlock('w:dateFormat', 'w:val', 'd/M/yyyy');
$xmlWriter->writeElementBlock('w:lid', 'w:val', 'en-US');
$xmlWriter->writeElementBlock('w:storeMappedDataAs', 'w:val', 'dateTime');
$xmlWriter->writeElementBlock('w:calendar', 'w:val', 'gregorian');
$xmlWriter->endElement();
// w:date
}
示例12: 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
}
示例13: 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
}
示例14: writeFont
/**
* Write level font.
*
* @since 0.11.0
*
* @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param \PhpOffice\PhpWord\Style\NumberingLevel $level
* @return void
* @todo Use font style writer
*/
private function writeFont(XMLWriter $xmlWriter, NumberingLevel $level)
{
$font = $level->getFont();
$hint = $level->getHint();
$xmlWriter->startElement('w:rPr');
$xmlWriter->startElement('w:rFonts');
$xmlWriter->writeAttributeIf($font !== null, 'w:ascii', $font);
$xmlWriter->writeAttributeIf($font !== null, 'w:hAnsi', $font);
$xmlWriter->writeAttributeIf($font !== null, 'w:cs', $font);
$xmlWriter->writeAttributeIf($hint !== null, 'w:hint', $hint);
$xmlWriter->endElement();
// w:rFonts
$xmlWriter->endElement();
// w:rPr
}
示例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.");
}
}