2012-05-06 18:25:40 +02:00
|
|
|
<?php
|
2014-03-15 22:39:57 +07:00
|
|
|
include_once 'Sample_Header.php';
|
2012-05-06 18:25:40 +02:00
|
|
|
|
|
|
|
|
// New Word Document
|
2015-01-01 20:41:42 +04:00
|
|
|
echo date('H:i:s') , ' Create new PhpWord object' , EOL;
|
2014-03-23 10:32:08 +04:00
|
|
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
2014-05-01 23:56:55 +07:00
|
|
|
$phpWord->addFontStyle('rStyle', array('bold' => true, 'italic' => true, 'size' => 16, 'allCaps' => true, 'doubleStrikethrough' => true));
|
2014-03-20 16:54:12 +04:00
|
|
|
$phpWord->addParagraphStyle('pStyle', array('align' => 'center', 'spaceAfter' => 100));
|
|
|
|
|
$phpWord->addTitleStyle(1, array('bold' => true), array('spaceAfter' => 240));
|
2012-05-06 18:25:40 +02:00
|
|
|
|
|
|
|
|
// New portrait section
|
2014-04-02 11:02:56 +07:00
|
|
|
$section = $phpWord->addSection();
|
2012-05-06 18:25:40 +02:00
|
|
|
|
2014-03-13 19:09:35 +07:00
|
|
|
// Simple text
|
2015-01-01 20:41:42 +04:00
|
|
|
$section->addTitle(htmlspecialchars('Welcome to PhpWord'), 1);
|
|
|
|
|
$section->addText(htmlspecialchars('Hello World!'));
|
2012-05-06 18:25:40 +02:00
|
|
|
|
2014-03-13 19:09:35 +07:00
|
|
|
// Two text break
|
2012-05-06 18:25:40 +02:00
|
|
|
$section->addTextBreak(2);
|
|
|
|
|
|
2014-03-13 19:09:35 +07:00
|
|
|
// Defined style
|
2015-01-01 20:41:42 +04:00
|
|
|
$section->addText(htmlspecialchars('I am styled by a font style definition.'), 'rStyle');
|
|
|
|
|
$section->addText(htmlspecialchars('I am styled by a paragraph style definition.'), null, 'pStyle');
|
|
|
|
|
$section->addText(htmlspecialchars('I am styled by both font and paragraph style.'), 'rStyle', 'pStyle');
|
2014-05-13 02:43:44 +07:00
|
|
|
|
2014-06-04 22:57:59 +07:00
|
|
|
$section->addTextBreak();
|
2014-03-13 19:09:35 +07:00
|
|
|
|
|
|
|
|
// Inline font style
|
|
|
|
|
$fontStyle['name'] = 'Times New Roman';
|
|
|
|
|
$fontStyle['size'] = 20;
|
2014-05-13 02:43:44 +07:00
|
|
|
|
2014-06-04 22:57:59 +07:00
|
|
|
$textrun = $section->addTextRun();
|
2015-01-01 20:41:42 +04:00
|
|
|
$textrun->addText(htmlspecialchars('I am inline styled '), $fontStyle);
|
|
|
|
|
$textrun->addText(htmlspecialchars('with '));
|
|
|
|
|
$textrun->addText(htmlspecialchars('color'), array('color' => '996699'));
|
|
|
|
|
$textrun->addText(htmlspecialchars(', '));
|
|
|
|
|
$textrun->addText(htmlspecialchars('bold'), array('bold' => true));
|
|
|
|
|
$textrun->addText(htmlspecialchars(', '));
|
|
|
|
|
$textrun->addText(htmlspecialchars('italic'), array('italic' => true));
|
|
|
|
|
$textrun->addText(htmlspecialchars(', '));
|
|
|
|
|
$textrun->addText(htmlspecialchars('underline'), array('underline' => 'dash'));
|
|
|
|
|
$textrun->addText(htmlspecialchars(', '));
|
|
|
|
|
$textrun->addText(htmlspecialchars('strikethrough'), array('strikethrough' => true));
|
|
|
|
|
$textrun->addText(htmlspecialchars(', '));
|
|
|
|
|
$textrun->addText(htmlspecialchars('doubleStrikethrough'), array('doubleStrikethrough' => true));
|
|
|
|
|
$textrun->addText(htmlspecialchars(', '));
|
|
|
|
|
$textrun->addText(htmlspecialchars('superScript'), array('superScript' => true));
|
|
|
|
|
$textrun->addText(htmlspecialchars(', '));
|
|
|
|
|
$textrun->addText(htmlspecialchars('subScript'), array('subScript' => true));
|
|
|
|
|
$textrun->addText(htmlspecialchars(', '));
|
|
|
|
|
$textrun->addText(htmlspecialchars('smallCaps'), array('smallCaps' => true));
|
|
|
|
|
$textrun->addText(htmlspecialchars(', '));
|
|
|
|
|
$textrun->addText(htmlspecialchars('allCaps'), array('allCaps' => true));
|
|
|
|
|
$textrun->addText(htmlspecialchars(', '));
|
|
|
|
|
$textrun->addText(htmlspecialchars('fgColor'), array('fgColor' => 'yellow'));
|
|
|
|
|
$textrun->addText(htmlspecialchars(', '));
|
|
|
|
|
$textrun->addText(htmlspecialchars('scale'), array('scale' => 200));
|
|
|
|
|
$textrun->addText(htmlspecialchars(', '));
|
|
|
|
|
$textrun->addText(htmlspecialchars('spacing'), array('spacing' => 120));
|
|
|
|
|
$textrun->addText(htmlspecialchars(', '));
|
|
|
|
|
$textrun->addText(htmlspecialchars('kerning'), array('kerning' => 10));
|
|
|
|
|
$textrun->addText(htmlspecialchars('. '));
|
2014-03-13 19:09:35 +07:00
|
|
|
|
|
|
|
|
// Link
|
2015-01-01 20:41:42 +04:00
|
|
|
$section->addLink('http://www.google.com', htmlspecialchars('Google'));
|
2014-03-13 19:09:35 +07:00
|
|
|
$section->addTextBreak();
|
|
|
|
|
|
|
|
|
|
// Image
|
2014-03-14 00:49:27 +07:00
|
|
|
$section->addImage('resources/_earth.jpg', array('width'=>18, 'height'=>18));
|
2012-05-06 18:25:40 +02:00
|
|
|
|
2014-03-12 21:55:20 +07:00
|
|
|
// Save file
|
2014-04-12 10:12:24 +07:00
|
|
|
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
|
|
|
|
if (!CLI) {
|
|
|
|
|
include_once 'Sample_Footer.php';
|
2014-03-12 21:55:20 +07:00
|
|
|
}
|