本文整理汇总了PHP中PhpOffice\PhpWord\PhpWord::getDocumentProperties方法的典型用法代码示例。如果您正苦于以下问题:PHP PhpWord::getDocumentProperties方法的具体用法?PHP PhpWord::getDocumentProperties怎么用?PHP PhpWord::getDocumentProperties使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PhpOffice\PhpWord\PhpWord
的用法示例。
在下文中一共展示了PhpWord::getDocumentProperties方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testSetGetDocumentProperties
/**
* Test set/get document properties
*/
public function testSetGetDocumentProperties()
{
$phpWord = new PhpWord();
$creator = 'PhpWord';
$properties = $phpWord->getDocumentProperties();
$properties->setCreator($creator);
$phpWord->setDocumentProperties($properties);
$this->assertEquals($creator, $phpWord->getDocumentProperties()->getCreator());
}
示例2: read
/**
* Read meta.xml
*
* @param \PhpOffice\PhpWord\PhpWord $phpWord
* @todo Process property type
*/
public function read(PhpWord &$phpWord)
{
$xmlReader = new XMLReader();
$xmlReader->getDomFromZip($this->docFile, $this->xmlFile);
$docProps = $phpWord->getDocumentProperties();
$metaNode = $xmlReader->getElement('office:meta');
// Standard properties
$properties = array('title' => 'dc:title', 'subject' => 'dc:subject', 'description' => 'dc:description', 'keywords' => 'meta:keyword', 'creator' => 'meta:initial-creator', 'lastModifiedBy' => 'dc:creator');
foreach ($properties as $property => $path) {
$method = "set{$property}";
$propertyNode = $xmlReader->getElement($path, $metaNode);
if ($propertyNode !== null && method_exists($docProps, $method)) {
$docProps->{$method}($propertyNode->nodeValue);
}
}
// Custom properties
$propertyNodes = $xmlReader->getElements('meta:user-defined', $metaNode);
foreach ($propertyNodes as $propertyNode) {
$property = $xmlReader->getAttribute('meta:name', $propertyNode);
// Set category, company, and manager property
if (in_array($property, array('Category', 'Company', 'Manager'))) {
$method = "set{$property}";
$docProps->{$method}($propertyNode->nodeValue);
// Set other custom properties
} else {
$docProps->setCustomProperty($property, $propertyNode->nodeValue);
}
}
}
示例3: testSave
/**
* Save
*/
public function testSave()
{
$localImage = __DIR__ . "/../_files/images/PhpWord.png";
$archiveImage = 'zip://' . __DIR__ . '/../_files/documents/reader.docx#word/media/image1.jpeg';
$gdImage = 'http://php.net/images/logos/php-med-trans-light.gif';
$objectSrc = __DIR__ . "/../_files/documents/sheet.xls";
$file = __DIR__ . "/../_files/temp.html";
$phpWord = new PhpWord();
$docProps = $phpWord->getDocumentProperties();
$docProps->setTitle('HTML Test');
$phpWord->addTitleStyle(1, array('bold' => true));
$phpWord->addFontStyle('Font', array('name' => 'Verdana', 'size' => 11, 'color' => 'FF0000', 'fgColor' => 'FF0000'));
$phpWord->addParagraphStyle('Paragraph', array('align' => 'center', 'spaceAfter' => 20, 'spaceBefore' => 20));
$section = $phpWord->addSection();
$section->addText('Test 1', 'Font', 'Paragraph');
$section->addTextBreak();
$section->addText('Test 2', array('name' => 'Tahoma', 'bold' => true, 'italic' => true, 'subscript' => true));
$section->addLink('http://test.com');
$section->addTitle('Test', 1);
$section->addPageBreak();
$section->addListItem('Test');
$section->addImage($localImage);
$section->addImage($archiveImage);
$section->addImage($gdImage);
$section->addObject($objectSrc);
$section->addFootnote();
$section->addEndnote();
$section = $phpWord->addSection();
$textrun = $section->addTextRun(array('align' => 'center'));
$textrun->addText('Test 3');
$textrun->addTextBreak();
$textrun = $section->addTextRun('Paragraph');
$textrun->addLink('http://test.com');
$textrun->addImage($localImage);
$textrun->addFootnote()->addText('Footnote');
$textrun->addEndnote()->addText('Endnote');
$section = $phpWord->addSection();
$table = $section->addTable();
$cell = $table->addRow()->addCell();
$cell->addText('Test 1', array('superscript' => true, 'underline' => 'dash', 'strikethrough' => true));
$cell->addTextRun();
$cell->addLink('http://test.com');
$cell->addTextBreak();
$cell->addListItem('Test');
$cell->addImage($localImage);
$cell->addObject($objectSrc);
$cell->addFootnote();
$cell->addEndnote();
$cell = $table->addRow()->addCell();
$writer = new HTML($phpWord);
$writer->save($file);
$this->assertTrue(file_exists($file));
unlink($file);
}
示例4: read
/**
* Read custom document properties
*
* @param \PhpOffice\PhpWord\PhpWord $phpWord
*/
public function read(PhpWord &$phpWord)
{
$xmlReader = new XMLReader();
$xmlReader->getDomFromZip($this->docFile, $this->xmlFile);
$docProps = $phpWord->getDocumentProperties();
$nodes = $xmlReader->getElements('*');
if ($nodes->length > 0) {
foreach ($nodes as $node) {
$propertyName = $xmlReader->getAttribute('name', $node);
$attributeNode = $xmlReader->getElement('*', $node);
$attributeType = $attributeNode->nodeName;
$attributeValue = $attributeNode->nodeValue;
$attributeValue = DocumentProperties::convertProperty($attributeValue, $attributeType);
$attributeType = DocumentProperties::convertPropertyType($attributeType);
$docProps->setCustomProperty($propertyName, $attributeValue, $attributeType);
}
}
}
示例5: testWriteContent
/**
* Test write content
*/
public function testWriteContent()
{
$imageSrc = __DIR__ . "/../../../_files/images/PhpWord.png";
$objectSrc = __DIR__ . "/../../../_files/documents/sheet.xls";
$expected = 'Expected';
$phpWord = new PhpWord();
$docProps = $phpWord->getDocumentProperties();
$docProps->setCustomProperty('Company', 'PHPWord');
$phpWord->setDefaultFontName('Verdana');
$phpWord->addFontStyle('Font', array('size' => 11));
$phpWord->addParagraphStyle('Paragraph', array('align' => 'center'));
$phpWord->addTableStyle('tblStyle', array('width' => 100));
$section = $phpWord->addSection(array('colsNum' => 2));
$section->addText($expected);
$section->addText('Test font style', 'Font');
$section->addText('Test paragraph style', null, 'Paragraph');
$section->addLink('http://test.com', 'Test link');
$section->addTitle('Test title', 1);
$section->addTextBreak();
$section->addPageBreak();
$section->addListItem('Test list item');
$section->addImage($imageSrc, array('width' => 50));
$section->addObject($objectSrc);
$section->addTOC();
$textrun = $section->addTextRun();
$textrun->addText('Test text run');
$table = $section->addTable(array('width' => 50));
$cell = $table->addRow()->addCell();
$cell = $table->addRow()->addCell();
$cell->addText('Test');
$cell->addLink('http://test.com', 'Test link');
$cell->addTextBreak();
$cell->addListItem('Test list item');
$cell->addImage($imageSrc);
$cell->addObject($objectSrc);
$textrun = $cell->addTextRun();
$textrun->addText('Test text run');
$footer = $section->addFooter();
$footer->addPreserveText('{PAGE}');
$table = $section->addTable('tblStyle')->addRow()->addCell();
$doc = TestHelperDOCX::getDocument($phpWord, 'ODText');
$element = "/office:document-content/office:body/office:text/text:section/text:p";
$this->assertEquals($expected, $doc->getElement($element, 'content.xml')->nodeValue);
}
示例6: read
/**
* Read core/extended document properties
*
* @param \PhpOffice\PhpWord\PhpWord $phpWord
*/
public function read(PhpWord &$phpWord)
{
$xmlReader = new XMLReader();
$xmlReader->getDomFromZip($this->docFile, $this->xmlFile);
$docProps = $phpWord->getDocumentProperties();
$nodes = $xmlReader->getElements('*');
if ($nodes->length > 0) {
foreach ($nodes as $node) {
if (!array_key_exists($node->nodeName, $this->mapping)) {
continue;
}
$method = $this->mapping[$node->nodeName];
$value = $node->nodeValue == '' ? null : $node->nodeValue;
if (array_key_exists($node->nodeName, $this->callbacks)) {
$value = $this->callbacks[$node->nodeName]($value);
}
if (method_exists($docProps, $method)) {
$docProps->{$method}($value);
}
}
}
}