2012-05-06 18:25:40 +02:00
|
|
|
<?php
|
2022-09-16 11:45:45 +02:00
|
|
|
|
2017-09-27 00:40:08 +02:00
|
|
|
use PhpOffice\PhpWord\Style\Font;
|
|
|
|
|
|
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;
|
2017-09-27 00:40:08 +02:00
|
|
|
|
|
|
|
|
$languageEnGb = new \PhpOffice\PhpWord\Style\Language(\PhpOffice\PhpWord\Style\Language::EN_GB);
|
|
|
|
|
|
2014-03-23 10:32:08 +04:00
|
|
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
2017-09-27 00:40:08 +02:00
|
|
|
$phpWord->getSettings()->setThemeFontLang($languageEnGb);
|
2016-06-04 20:06:37 +04:00
|
|
|
|
|
|
|
|
$fontStyleName = 'rStyle';
|
2022-09-16 11:45:45 +02:00
|
|
|
$phpWord->addFontStyle($fontStyleName, ['bold' => true, 'italic' => true, 'size' => 16, 'allCaps' => true, 'doubleStrikethrough' => true]);
|
2016-06-04 20:06:37 +04:00
|
|
|
|
|
|
|
|
$paragraphStyleName = 'pStyle';
|
2022-09-16 11:45:45 +02:00
|
|
|
$phpWord->addParagraphStyle($paragraphStyleName, ['alignment' => \PhpOffice\PhpWord\SimpleType\Jc::CENTER, 'spaceAfter' => 100]);
|
2016-06-04 20:06:37 +04:00
|
|
|
|
2022-09-16 11:45:45 +02:00
|
|
|
$phpWord->addTitleStyle(1, ['bold' => true], ['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
|
2016-06-04 20:06:37 +04:00
|
|
|
$section->addTitle('Welcome to PhpWord', 1);
|
|
|
|
|
$section->addText('Hello World!');
|
2012-05-06 18:25:40 +02:00
|
|
|
|
2017-09-27 00:40:08 +02:00
|
|
|
// $pStyle = new Font();
|
|
|
|
|
// $pStyle->setLang()
|
2022-09-16 11:45:45 +02:00
|
|
|
$section->addText('Ce texte-ci est en français.', ['lang' => \PhpOffice\PhpWord\Style\Language::FR_BE]);
|
2017-09-27 00:40:08 +02:00
|
|
|
|
2014-03-13 19:09:35 +07:00
|
|
|
// Two text break
|
2012-05-06 18:25:40 +02:00
|
|
|
$section->addTextBreak(2);
|
|
|
|
|
|
2016-06-04 20:06:37 +04:00
|
|
|
// Define styles
|
|
|
|
|
$section->addText('I am styled by a font style definition.', $fontStyleName);
|
|
|
|
|
$section->addText('I am styled by a paragraph style definition.', null, $paragraphStyleName);
|
|
|
|
|
$section->addText('I am styled by both font and paragraph style.', $fontStyleName, $paragraphStyleName);
|
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();
|
2016-06-04 20:06:37 +04:00
|
|
|
$textrun->addText('I am inline styled ', $fontStyle);
|
|
|
|
|
$textrun->addText('with ');
|
2022-09-16 11:45:45 +02:00
|
|
|
$textrun->addText('color', ['color' => '996699']);
|
2016-06-04 20:06:37 +04:00
|
|
|
$textrun->addText(', ');
|
2022-09-16 11:45:45 +02:00
|
|
|
$textrun->addText('bold', ['bold' => true]);
|
2016-06-04 20:06:37 +04:00
|
|
|
$textrun->addText(', ');
|
2022-09-16 11:45:45 +02:00
|
|
|
$textrun->addText('italic', ['italic' => true]);
|
2016-06-04 20:06:37 +04:00
|
|
|
$textrun->addText(', ');
|
2022-09-16 11:45:45 +02:00
|
|
|
$textrun->addText('underline', ['underline' => 'dash']);
|
2016-06-04 20:06:37 +04:00
|
|
|
$textrun->addText(', ');
|
2022-09-16 11:45:45 +02:00
|
|
|
$textrun->addText('strikethrough', ['strikethrough' => true]);
|
2016-06-04 20:06:37 +04:00
|
|
|
$textrun->addText(', ');
|
2022-09-16 11:45:45 +02:00
|
|
|
$textrun->addText('doubleStrikethrough', ['doubleStrikethrough' => true]);
|
2016-06-04 20:06:37 +04:00
|
|
|
$textrun->addText(', ');
|
2022-09-16 11:45:45 +02:00
|
|
|
$textrun->addText('superScript', ['superScript' => true]);
|
2016-06-04 20:06:37 +04:00
|
|
|
$textrun->addText(', ');
|
2022-09-16 11:45:45 +02:00
|
|
|
$textrun->addText('subScript', ['subScript' => true]);
|
2016-06-04 20:06:37 +04:00
|
|
|
$textrun->addText(', ');
|
2022-09-16 11:45:45 +02:00
|
|
|
$textrun->addText('smallCaps', ['smallCaps' => true]);
|
2016-06-04 20:06:37 +04:00
|
|
|
$textrun->addText(', ');
|
2022-09-16 11:45:45 +02:00
|
|
|
$textrun->addText('allCaps', ['allCaps' => true]);
|
2016-06-04 20:06:37 +04:00
|
|
|
$textrun->addText(', ');
|
2022-09-16 11:45:45 +02:00
|
|
|
$textrun->addText('fgColor', ['fgColor' => 'yellow']);
|
2016-06-04 20:06:37 +04:00
|
|
|
$textrun->addText(', ');
|
2022-09-16 11:45:45 +02:00
|
|
|
$textrun->addText('scale', ['scale' => 200]);
|
2016-06-04 20:06:37 +04:00
|
|
|
$textrun->addText(', ');
|
2022-09-16 11:45:45 +02:00
|
|
|
$textrun->addText('spacing', ['spacing' => 120]);
|
2016-06-04 20:06:37 +04:00
|
|
|
$textrun->addText(', ');
|
2022-09-16 11:45:45 +02:00
|
|
|
$textrun->addText('kerning', ['kerning' => 10]);
|
2016-06-04 20:06:37 +04:00
|
|
|
$textrun->addText('. ');
|
2014-03-13 19:09:35 +07:00
|
|
|
|
|
|
|
|
// Link
|
2016-06-04 20:06:37 +04:00
|
|
|
$section->addLink('https://github.com/PHPOffice/PHPWord', 'PHPWord on GitHub');
|
2014-03-13 19:09:35 +07:00
|
|
|
$section->addTextBreak();
|
|
|
|
|
|
|
|
|
|
// Image
|
2022-09-16 11:45:45 +02:00
|
|
|
$section->addImage('resources/_earth.jpg', ['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
|
|
|
}
|