add exmpales
[pear-examples] / Document_Word_Writer / Examples / Textrun.php
1 <?php
2 ini_set('include_path', __DIR__  . '/../../..:.');
3 require_once __DIR__ . '/../Writer.php';
4 require_once __DIR__ . '/../Writer/Style/Font.php';
5
6 // New Word Document
7 $PHPWord = new Document_Word_Writer();
8
9 // New portrait section
10 $section = $PHPWord->createSection();
11
12 // Add style definitions
13 $PHPWord->addParagraphStyle('pStyle', array('spacing'=>100));
14 $PHPWord->addFontStyle('BoldText', array('bold'=>true));
15 $PHPWord->addFontStyle('ColoredText', array('color'=>'FF8080'));
16 $PHPWord->addLinkStyle('NLink', array('color'=>'0000FF', 'underline'=>Document_Word_Writer_Style_Font::UNDERLINE_SINGLE));
17
18 // Add text elements
19 $textrun = $section->createTextRun('pStyle');
20
21 $textrun->addText('Each textrun can contain native text or link elements.');
22 $textrun->addText(' No break is placed after adding an element.', 'BoldText');
23 $textrun->addText(' All elements are placed inside a paragraph with the optionally given p-Style.', 'ColoredText');
24 $textrun->addText(' The best search engine: ');
25 $textrun->addLink('http://www.google.com', null, 'NLink');
26 $textrun->addText('. Also not bad: ');
27 $textrun->addLink('http://www.bing.com', null, 'NLink');
28
29
30
31 // Save File
32 require_once __DIR__ . '/../Writer/IOFactory.php';
33 $objWriter = Document_Word_Writer_IOFactory::createWriter($PHPWord, 'Word2007');
34 $objWriter->save('/tmp/Textrun.docx');
35 ?>