本文整理汇总了PHP中PhpOffice\PhpWord\PhpWord::addParagraphStyle方法的典型用法代码示例。如果您正苦于以下问题:PHP PhpWord::addParagraphStyle方法的具体用法?PHP PhpWord::addParagraphStyle怎么用?PHP PhpWord::addParagraphStyle使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PhpOffice\PhpWord\PhpWord
的用法示例。
在下文中一共展示了PhpWord::addParagraphStyle方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: read
/**
* Read styles.xml.
*
* @param \PhpOffice\PhpWord\PhpWord $phpWord
* @return void
*/
public function read(PhpWord $phpWord)
{
$xmlReader = new XMLReader();
$xmlReader->getDomFromZip($this->docFile, $this->xmlFile);
$nodes = $xmlReader->getElements('w:style');
if ($nodes->length > 0) {
foreach ($nodes as $node) {
$type = $xmlReader->getAttribute('w:type', $node);
$name = $xmlReader->getAttribute('w:styleId', $node);
if (is_null($name)) {
$name = $xmlReader->getAttribute('w:val', $node, 'w:name');
}
preg_match('/Heading(\\d)/', $name, $headingMatches);
// $default = ($xmlReader->getAttribute('w:default', $node) == 1);
switch ($type) {
case 'paragraph':
$paragraphStyle = $this->readParagraphStyle($xmlReader, $node);
$fontStyle = $this->readFontStyle($xmlReader, $node);
if (!empty($headingMatches)) {
$phpWord->addTitleStyle($headingMatches[1], $fontStyle, $paragraphStyle);
} else {
if (empty($fontStyle)) {
if (is_array($paragraphStyle)) {
$phpWord->addParagraphStyle($name, $paragraphStyle);
}
} else {
$phpWord->addFontStyle($name, $fontStyle, $paragraphStyle);
}
}
break;
case 'character':
$fontStyle = $this->readFontStyle($xmlReader, $node);
if (!empty($fontStyle)) {
$phpWord->addFontStyle($name, $fontStyle);
}
break;
case 'table':
$tStyle = $this->readTableStyle($xmlReader, $node);
if (!empty($tStyle)) {
$phpWord->addTableStyle($name, $tStyle);
}
break;
}
}
}
}
示例2: testWriteStyles
/**
* Test write styles
*/
public function testWriteStyles()
{
$phpWord = new PhpWord();
$pStyle = array('align' => 'both');
$pBase = array('basedOn' => 'Normal');
$pNew = array('basedOn' => 'Base Style', 'next' => 'Normal');
$rStyle = array('size' => 20);
$tStyle = array('bgColor' => 'FF0000', 'cellMarginTop' => 120, 'cellMarginBottom' => 120, 'cellMarginLeft' => 120, 'cellMarginRight' => 120, 'borderTopSize' => 120, 'borderBottomSize' => 120, 'borderLeftSize' => 120, 'borderRightSize' => 120, 'borderInsideHSize' => 120, 'borderInsideVSize' => 120);
$phpWord->setDefaultParagraphStyle($pStyle);
$phpWord->addParagraphStyle('Base Style', $pBase);
$phpWord->addParagraphStyle('New Style', $pNew);
$phpWord->addFontStyle('New Style', $rStyle, $pStyle);
$phpWord->addTableStyle('Table Style', $tStyle, $tStyle);
$phpWord->addTitleStyle(1, $rStyle, $pStyle);
$doc = TestHelperDOCX::getDocument($phpWord);
$file = 'word/styles.xml';
// Normal style generated?
$path = '/w:styles/w:style[@w:styleId="Normal"]/w:name';
$element = $doc->getElement($path, $file);
$this->assertEquals('Normal', $element->getAttribute('w:val'));
// Parent style referenced?
$path = '/w:styles/w:style[@w:styleId="New Style"]/w:basedOn';
$element = $doc->getElement($path, $file);
$this->assertEquals('Base Style', $element->getAttribute('w:val'));
// Next paragraph style correct?
$path = '/w:styles/w:style[@w:styleId="New Style"]/w:next';
$element = $doc->getElement($path, $file);
$this->assertEquals('Normal', $element->getAttribute('w:val'));
}
示例3: testSave
/**
* Save
*/
public function testSave()
{
$imageSrc = __DIR__ . '/../_files/images/PhpWord.png';
$objectSrc = __DIR__ . '/../_files/documents/sheet.xls';
$file = __DIR__ . '/../_files/temp.odt';
$phpWord = new PhpWord();
$phpWord->addFontStyle('Font', array('size' => 11));
$phpWord->addParagraphStyle('Paragraph', array('alignment' => Jc::CENTER));
$section = $phpWord->addSection();
$section->addText(htmlspecialchars('Test 1', ENT_COMPAT, 'UTF-8'), 'Font');
$section->addTextBreak();
$section->addText(htmlspecialchars('Test 2', ENT_COMPAT, 'UTF-8'), null, 'Paragraph');
$section->addLink('https://github.com/PHPOffice/PHPWord');
$section->addTitle(htmlspecialchars('Test', ENT_COMPAT, 'UTF-8'), 1);
$section->addPageBreak();
$section->addTable()->addRow()->addCell()->addText(htmlspecialchars('Test', ENT_COMPAT, 'UTF-8'));
$section->addListItem(htmlspecialchars('Test', ENT_COMPAT, 'UTF-8'));
$section->addImage($imageSrc);
$section->addObject($objectSrc);
$section->addTOC();
$section = $phpWord->addSection();
$textrun = $section->addTextRun();
$textrun->addText(htmlspecialchars('Test 3', ENT_COMPAT, 'UTF-8'));
$writer = new ODText($phpWord);
$writer->save($file);
$this->assertTrue(file_exists($file));
unlink($file);
}
示例4: testSave
/**
* Save
*/
public function testSave()
{
$imageSrc = __DIR__ . "/../_files/images/PhpWord.png";
$objectSrc = __DIR__ . "/../_files/documents/sheet.xls";
$file = __DIR__ . "/../_files/temp.rtf";
$phpWord = new PhpWord();
$phpWord->addFontStyle('Font', array('name' => 'Verdana', 'size' => 11, 'color' => 'FF0000', 'fgColor' => 'FF0000'));
$phpWord->addParagraphStyle('Paragraph', array('align' => 'center'));
$section = $phpWord->addSection();
$section->addText('Test 1', 'Font', 'Paragraph');
$section->addTextBreak();
$section->addText('Test 2', array('name' => 'Tahoma', 'bold' => true, 'italic' => true));
$section->addLink('http://test.com');
$section->addTitle('Test', 1);
$section->addPageBreak();
$section->addTable();
$section->addListItem('Test');
$section->addImage($imageSrc);
$section->addObject($objectSrc);
$section->addTOC();
$section = $phpWord->addSection();
$textrun = $section->addTextRun();
$textrun->addText('Test 3');
$textrun->addTextBreak();
$writer = new RTF($phpWord);
$writer->save($file);
$this->assertTrue(file_exists($file));
unlink($file);
}
示例5: testSave
/**
* Save
*/
public function testSave()
{
$imageSrc = __DIR__ . '/../_files/images/PhpWord.png';
$objectSrc = __DIR__ . '/../_files/documents/sheet.xls';
$file = __DIR__ . '/../_files/temp.rtf';
$phpWord = new PhpWord();
$phpWord->addFontStyle('Font', array('name' => 'Verdana', 'size' => 11, 'color' => 'FF0000', 'fgColor' => '00FF00'));
$phpWord->addParagraphStyle('Paragraph', array('alignment' => Jc::CENTER));
$section = $phpWord->addSection();
$section->addText(htmlspecialchars('Test 1', ENT_COMPAT, 'UTF-8'), 'Font', 'Paragraph');
$section->addTextBreak();
$section->addText(htmlspecialchars('Test 2', ENT_COMPAT, 'UTF-8'), array('name' => 'Tahoma', 'bold' => true, 'italic' => true));
$section->addLink('https://github.com/PHPOffice/PHPWord');
$section->addTitle(htmlspecialchars('Test', ENT_COMPAT, 'UTF-8'), 1);
$section->addPageBreak();
// Rowspan
$table = $section->addTable();
$table->addRow()->addCell(null, array('vMerge' => 'restart'))->addText('Test');
$table->addRow()->addCell(null, array('vMerge' => 'continue'))->addText('Test');
// Nested table
$cell = $section->addTable()->addRow()->addCell();
$cell->addTable()->addRow()->addCell();
$section->addListItem(htmlspecialchars('Test', ENT_COMPAT, 'UTF-8'));
$section->addImage($imageSrc);
$section->addObject($objectSrc);
$section->addTOC();
$section = $phpWord->addSection();
$textrun = $section->addTextRun();
$textrun->addText(htmlspecialchars('Test 3', ENT_COMPAT, 'UTF-8'));
$textrun->addTextBreak();
$writer = new RTF($phpWord);
$writer->save($file);
$this->assertTrue(file_exists($file));
@unlink($file);
}
示例6: testSave
/**
* Save
*/
public function testSave()
{
$localImage = __DIR__ . '/../_files/images/earth.jpg';
$remoteImage = 'http://php.net//images/logos/php-med-trans-light.gif';
$phpWord = new PhpWord();
$phpWord->addFontStyle('Font', array('size' => 11));
$phpWord->addParagraphStyle('Paragraph', array('alignment' => Jc::CENTER));
$section = $phpWord->addSection();
$section->addText(htmlspecialchars('Test 1', ENT_COMPAT, 'UTF-8'), 'Font', 'Paragraph');
$section->addTextBreak();
$section->addText(htmlspecialchars('Test 2', ENT_COMPAT, 'UTF-8'));
$section = $phpWord->addSection();
$textrun = $section->addTextRun();
$textrun->addText(htmlspecialchars('Test 3', ENT_COMPAT, 'UTF-8'));
$footnote = $textrun->addFootnote();
$footnote->addLink('https://github.com/PHPOffice/PHPWord');
$header = $section->addHeader();
$header->addImage($localImage);
$footer = $section->addFooter();
$footer->addImage($remoteImage);
$writer = new Word2007($phpWord);
$file = __DIR__ . '/../_files/temp.docx';
$writer->save($file);
$this->assertTrue(file_exists($file));
unlink($file);
}
示例7: testSave
/**
* Save
*/
public function testSave()
{
$localImage = __DIR__ . '/../_files/images/earth.jpg';
$remoteImage = 'http://php.net//images/logos/php-med-trans-light.gif';
$phpWord = new PhpWord();
$phpWord->addFontStyle('Font', array('size' => 11));
$phpWord->addParagraphStyle('Paragraph', array('align' => 'center'));
$section = $phpWord->addSection();
$section->addText('Test 1', 'Font', 'Paragraph');
$section->addTextBreak();
$section->addText('Test 2');
$section = $phpWord->addSection();
$textrun = $section->addTextRun();
$textrun->addText('Test 3');
$footnote = $textrun->addFootnote();
$footnote->addLink('http://test.com');
$header = $section->addHeader();
$header->addImage($localImage);
$footer = $section->addFooter();
$footer->addImage($remoteImage);
$writer = new Word2007($phpWord);
$file = __DIR__ . "/../_files/temp.docx";
$writer->save($file);
$this->assertTrue(file_exists($file));
unlink($file);
}
示例8: testSave
/**
* Save
*/
public function testSave()
{
$imageSrc = __DIR__ . "/../_files/images/PhpWord.png";
$objectSrc = __DIR__ . "/../_files/documents/sheet.xls";
$file = __DIR__ . "/../_files/temp.odt";
$phpWord = new PhpWord();
$phpWord->addFontStyle('Font', array('size' => 11));
$phpWord->addParagraphStyle('Paragraph', array('align' => 'center'));
$section = $phpWord->addSection();
$section->addText('Test 1', 'Font');
$section->addTextBreak();
$section->addText('Test 2', null, 'Paragraph');
$section->addLink('http://test.com');
$section->addTitle('Test', 1);
$section->addPageBreak();
$section->addTable()->addRow()->addCell()->addText('Test');
$section->addListItem('Test');
$section->addImage($imageSrc);
$section->addObject($objectSrc);
$section->addTOC();
$section = $phpWord->addSection();
$textrun = $section->addTextRun();
$textrun->addText('Test 3');
$writer = new ODText($phpWord);
$writer->save($file);
$this->assertTrue(file_exists($file));
unlink($file);
}
示例9: testTabsStyle
/**
* Test if the tabs has been created properly
*/
public function testTabsStyle()
{
$phpWord = new PhpWord();
$phpWord->addParagraphStyle('tabbed', array('tabs' => array(new Tab('left', 1440, 'dot'))));
$doc = TestHelperDOCX::getDocument($phpWord);
$file = 'word/styles.xml';
$path = '/w:styles/w:style[@w:styleId="tabbed"]/w:pPr/w:tabs/w:tab[1]';
$element = $doc->getElement($path, $file);
$this->assertEquals('left', $element->getAttribute('w:val'));
$this->assertEquals(1440, $element->getAttribute('w:pos'));
$this->assertEquals('dot', $element->getAttribute('w:leader'));
}
示例10: testWriteFootnotes
/**
* Write footnotes
*/
public function testWriteFootnotes()
{
$phpWord = new PhpWord();
$phpWord->addParagraphStyle('pStyle', array('align' => 'left'));
$section = $phpWord->addSection();
$section->addText(htmlspecialchars('Text', ENT_COMPAT, 'UTF-8'));
$footnote1 = $section->addFootnote('pStyle');
$footnote1->addText(htmlspecialchars('Footnote', ENT_COMPAT, 'UTF-8'));
$footnote1->addTextBreak();
$footnote1->addLink('https://github.com/PHPOffice/PHPWord');
$footnote2 = $section->addEndnote(array('align' => 'left'));
$footnote2->addText(htmlspecialchars('Endnote', ENT_COMPAT, 'UTF-8'));
$doc = TestHelperDOCX::getDocument($phpWord);
$this->assertTrue($doc->elementExists('/w:document/w:body/w:p/w:r/w:footnoteReference'));
$this->assertTrue($doc->elementExists('/w:document/w:body/w:p/w:r/w:endnoteReference'));
}
示例11: testWriteFootnotes
/**
* Write footnotes
*/
public function testWriteFootnotes()
{
$phpWord = new PhpWord();
$phpWord->addParagraphStyle('pStyle', array('align' => 'left'));
$section = $phpWord->addSection();
$section->addText('Text');
$footnote1 = $section->addFootnote('pStyle');
$footnote1->addText('Footnote');
$footnote1->addTextBreak();
$footnote1->addLink('http://google.com');
$footnote2 = $section->addEndnote(array('align' => 'left'));
$footnote2->addText('Endnote');
$doc = TestHelperDOCX::getDocument($phpWord);
$this->assertTrue($doc->elementExists("/w:document/w:body/w:p/w:r/w:footnoteReference"));
$this->assertTrue($doc->elementExists("/w:document/w:body/w:p/w:r/w:endnoteReference"));
}
示例12: 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);
}
示例13: 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->getDocInfo();
$docProps->setCustomProperty('Company', 'PHPWord');
$phpWord->setDefaultFontName('Verdana');
$phpWord->addFontStyle('Font', array('size' => 11));
$phpWord->addParagraphStyle('Paragraph', array('alignment' => Jc::CENTER));
$phpWord->addTableStyle('tblStyle', array('width' => 100));
$section = $phpWord->addSection(array('colsNum' => 2));
$section->addText(htmlspecialchars($expected, ENT_COMPAT, 'UTF-8'));
$section->addText(htmlspecialchars('Test font style', ENT_COMPAT, 'UTF-8'), 'Font');
$section->addText(htmlspecialchars('Test paragraph style', ENT_COMPAT, 'UTF-8'), null, 'Paragraph');
$section->addLink('https://github.com/PHPOffice/PHPWord', htmlspecialchars('PHPWord on GitHub', ENT_COMPAT, 'UTF-8'));
$section->addTitle(htmlspecialchars('Test title', ENT_COMPAT, 'UTF-8'), 1);
$section->addTextBreak();
$section->addPageBreak();
$section->addListItem(htmlspecialchars('Test list item', ENT_COMPAT, 'UTF-8'));
$section->addImage($imageSrc, array('width' => 50));
$section->addObject($objectSrc);
$section->addTOC();
$textrun = $section->addTextRun();
$textrun->addText(htmlspecialchars('Test text run', ENT_COMPAT, 'UTF-8'));
$table = $section->addTable(array('width' => 50));
$cell = $table->addRow()->addCell();
$cell = $table->addRow()->addCell();
$cell->addText(htmlspecialchars('Test', ENT_COMPAT, 'UTF-8'));
$cell->addLink('https://github.com/PHPOffice/PHPWord', htmlspecialchars('PHPWord on GitHub', ENT_COMPAT, 'UTF-8'));
$cell->addTextBreak();
$cell->addListItem(htmlspecialchars('Test list item', ENT_COMPAT, 'UTF-8'));
$cell->addImage($imageSrc);
$cell->addObject($objectSrc);
$textrun = $cell->addTextRun();
$textrun->addText(htmlspecialchars('Test text run', ENT_COMPAT, 'UTF-8'));
$footer = $section->addFooter();
$footer->addPreserveText(htmlspecialchars('{PAGE}', ENT_COMPAT, 'UTF-8'));
$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);
}
示例14: testWriteCheckbox
/**
* covers ::_writeCheckbox
*/
public function testWriteCheckbox()
{
$rStyle = 'rStyle';
$pStyle = 'pStyle';
$phpWord = new PhpWord();
$phpWord->addFontStyle($rStyle, array('bold' => true));
$phpWord->addParagraphStyle($pStyle, array('hanging' => 120, 'indent' => 120));
$section = $phpWord->addSection();
$section->addCheckbox('Check1', 'Test', $rStyle, $pStyle);
$doc = TestHelperDOCX::getDocument($phpWord);
$element = '/w:document/w:body/w:p/w:r/w:fldChar/w:ffData/w:name';
$this->assertEquals('Check1', $doc->getElementAttribute($element, 'w:val'));
}
示例15: getAutomaticStyles
/**
* Set automatic styles
*/
private function getAutomaticStyles(PhpWord $phpWord)
{
$sections = $phpWord->getSections();
$sectionCount = count($sections);
if ($sectionCount > 0) {
$paragraphStyleCount = 0;
$fontStyleCount = 0;
foreach ($sections as $section) {
$elements = $section->getElements();
foreach ($elements as $element) {
if ($element instanceof Text) {
$fontStyle = $element->getFontStyle();
$paragraphStyle = $element->getParagraphStyle();
// Font
if ($fontStyle instanceof Font) {
$fontStyleCount++;
$arrStyle = array('color' => $fontStyle->getColor(), 'name' => $fontStyle->getName());
$phpWord->addFontStyle('T' . $fontStyleCount, $arrStyle);
$element->setFontStyle('T' . $fontStyleCount);
// Paragraph
} elseif ($paragraphStyle instanceof Paragraph) {
$paragraphStyleCount++;
$phpWord->addParagraphStyle('P' . $paragraphStyleCount, array());
$element->setParagraphStyle('P' . $paragraphStyleCount);
}
}
}
}
}
}