GlisWeb framework
_test01.php
Vai alla documentazione di questo file.
1 <?php
2 
13  // inclusione del framework
14  require '../../../_src/_config.php';
15 
16  // namespace
19 
20  // inizializzo il linguaggio
21  $language = new \PhpOffice\PhpWord\Style\Language(\PhpOffice\PhpWord\Style\Language::EN_GB);
22 
23  // inizializzo il documento
24  $phpWord = new \PhpOffice\PhpWord\PhpWord();
25 
26  // setto il linguaggio
27  $phpWord->getSettings()->setThemeFontLang( $language );
28 
29  $fontStyleName = 'rStyle';
30 $phpWord->addFontStyle($fontStyleName, array('bold' => true, 'italic' => true, 'size' => 16, 'allCaps' => true, 'doubleStrikethrough' => true));
32 $phpWord->addParagraphStyle($paragraphStyleName, array('alignment' => \PhpOffice\PhpWord\SimpleType\Jc::CENTER, 'spaceAfter' => 100));
33 $phpWord->addTitleStyle(1, array('bold' => true), array('spaceAfter' => 240));
34 // New portrait section
35 $section = $phpWord->addSection();
36 // Simple text
37 $section->addTitle('Welcome to PhpWord', 1);
38 $section->addText('Hello World!');
39 // $pStyle = new Font();
40 // $pStyle->setLang()
41 $section->addText('Ce texte-ci est en français.', array('lang' => \PhpOffice\PhpWord\Style\Language::FR_BE));
42 // Two text break
43 $section->addTextBreak(2);
44 // Define styles
45 $section->addText('I am styled by a font style definition.', $fontStyleName);
46 $section->addText('I am styled by a paragraph style definition.', null, $paragraphStyleName);
47 $section->addText('I am styled by both font and paragraph style.', $fontStyleName, $paragraphStyleName);
48 $section->addTextBreak();
49 // Inline font style
50 $fontStyle['name'] = 'Times New Roman';
51 $fontStyle['size'] = 20;
52 $textrun = $section->addTextRun();
53 $textrun->addText('I am inline styled ', $fontStyle);
54 $textrun->addText('with ');
55 $textrun->addText('color', array('color' => '996699'));
56 $textrun->addText(', ');
57 $textrun->addText('bold', array('bold' => true));
58 $textrun->addText(', ');
59 $textrun->addText('italic', array('italic' => true));
60 $textrun->addText(', ');
61 $textrun->addText('underline', array('underline' => 'dash'));
62 $textrun->addText(', ');
63 $textrun->addText('strikethrough', array('strikethrough' => true));
64 $textrun->addText(', ');
65 $textrun->addText('doubleStrikethrough', array('doubleStrikethrough' => true));
66 $textrun->addText(', ');
67 $textrun->addText('superScript', array('superScript' => true));
68 $textrun->addText(', ');
69 $textrun->addText('subScript', array('subScript' => true));
70 $textrun->addText(', ');
71 $textrun->addText('smallCaps', array('smallCaps' => true));
72 $textrun->addText(', ');
73 $textrun->addText('allCaps', array('allCaps' => true));
74 $textrun->addText(', ');
75 $textrun->addText('fgColor', array('fgColor' => 'yellow'));
76 $textrun->addText(', ');
77 $textrun->addText('scale', array('scale' => 200));
78 $textrun->addText(', ');
79 $textrun->addText('spacing', array('spacing' => 120));
80 $textrun->addText(', ');
81 $textrun->addText('kerning', array('kerning' => 10));
82 $textrun->addText('. ');
83 // Link
84 $section->addLink('https://github.com/PHPOffice/PHPWord', 'PHPWord on GitHub');
85 $section->addTextBreak();
86 // Image
87 // $section->addImage('resources/_earth.jpg', array('width'=>18, 'height'=>18));
88 // Save file
89 #echo write($phpWord, basename(__FILE__, '.php'), $writers);
90 
91 // Saving the document as OOXML file...
92 $objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007', true);
93 // $objWriter->save('helloWorld.docx');
94 
95 header('Content-Description: File Transfer');
96 header('Content-Disposition: attachment; filename="helloWorld.docx"');
97 header('Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document');
98 header('Content-Transfer-Encoding: binary');
99 header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
100 header('Expires: 0');
101 $objWriter->save('php://output');
102 
103 // TODO fare buildDocx
104 
105 /*
106 NOTA l'esportazione in ODT non funziona granché, approfondire...
107 // Saving the document as ODF file...
108 $objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'ODText');
109 $objWriter->save('helloWorld.odt');
110 
111 header('Content-Description: File Transfer');
112 header('Content-Disposition: attachment; filename="helloWorld.odt"');
113 header('Content-Type: application/vnd.oasis.opendocument.text');
114 header('Content-Transfer-Encoding: binary');
115 header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
116 header('Expires: 0');
117 $objWriter->save('php://output');
118 */
119 
120 /*
121 // Saving the document as HTML file...
122 $objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'HTML');
123 $objWriter->save('helloWorld.html');
124 *
125 
126 ?>
$textrun
Definition: _test01.php:52
$language
Definition: _test01.php:21
$section
Definition: _test01.php:35
$paragraphStyleName
Definition: _test01.php:31
$objWriter
Definition: _test01.php:92
$phpWord
Definition: _test01.php:24
$fontStyleName
Definition: _test01.php:29
$fontStyle['name']
Definition: _test01.php:50