2014-03-07 23:08:09 +01:00
|
|
|
<?php
|
2014-03-15 22:39:57 +07:00
|
|
|
include_once 'Sample_Header.php';
|
2014-03-07 23:08:09 +01: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-04-01 15:01:30 +07:00
|
|
|
\PhpOffice\PhpWord\Settings::setCompatibility(false);
|
2014-03-07 23:08:09 +01:00
|
|
|
|
|
|
|
|
// New portrait section
|
2014-04-02 11:02:56 +07:00
|
|
|
$section = $phpWord->addSection();
|
2014-03-07 23:08:09 +01:00
|
|
|
|
|
|
|
|
// Add style definitions
|
2015-01-01 20:41:42 +04:00
|
|
|
$phpWord->addParagraphStyle('pStyle', array('spacing' => 100));
|
|
|
|
|
$phpWord->addFontStyle('BoldText', array('bold' => true));
|
|
|
|
|
$phpWord->addFontStyle('ColoredText', array('color' => 'FF8080'));
|
|
|
|
|
$phpWord->addLinkStyle(
|
|
|
|
|
'NLink',
|
|
|
|
|
array('color' => '0000FF', 'underline' => \PhpOffice\PhpWord\Style\Font::UNDERLINE_SINGLE)
|
|
|
|
|
);
|
2014-03-07 23:08:09 +01:00
|
|
|
|
|
|
|
|
// Add text elements
|
2014-04-02 11:02:56 +07:00
|
|
|
$textrun = $section->addTextRun('pStyle');
|
2015-02-06 22:28:31 +04:00
|
|
|
$textrun->addText(htmlspecialchars('This is some lead text in a paragraph with a following footnote. ', ENT_COMPAT, 'UTF-8'), 'pStyle');
|
2014-03-07 23:08:09 +01:00
|
|
|
|
2014-04-02 11:02:56 +07:00
|
|
|
$footnote = $textrun->addFootnote();
|
2015-02-06 22:28:31 +04:00
|
|
|
$footnote->addText(htmlspecialchars('Just like a textrun, a footnote can contain native texts. ', ENT_COMPAT, 'UTF-8'));
|
|
|
|
|
$footnote->addText(htmlspecialchars('No break is placed after adding an element. ', ENT_COMPAT, 'UTF-8'), 'BoldText');
|
|
|
|
|
$footnote->addText(htmlspecialchars('All elements are placed inside a paragraph. ', ENT_COMPAT, 'UTF-8'), 'ColoredText');
|
2014-03-29 00:57:23 +07:00
|
|
|
$footnote->addTextBreak();
|
2015-02-06 22:28:31 +04:00
|
|
|
$footnote->addText(htmlspecialchars('But you can insert a manual text break like above, ', ENT_COMPAT, 'UTF-8'));
|
|
|
|
|
$footnote->addText(htmlspecialchars('links like ', ENT_COMPAT, 'UTF-8'));
|
|
|
|
|
$footnote->addLink('https://github.com/PHPOffice/PHPWord', htmlspecialchars('PHPWord on GitHub', ENT_COMPAT, 'UTF-8'), 'NLink');
|
|
|
|
|
$footnote->addText(htmlspecialchars(', image like ', ENT_COMPAT, 'UTF-8'));
|
2014-04-01 15:01:30 +07:00
|
|
|
$footnote->addImage('resources/_earth.jpg', array('width' => 18, 'height' => 18));
|
2015-02-06 22:28:31 +04:00
|
|
|
$footnote->addText(htmlspecialchars(', or object like ', ENT_COMPAT, 'UTF-8'));
|
2014-04-02 09:01:44 +07:00
|
|
|
$footnote->addObject('resources/_sheet.xls');
|
2015-02-06 22:28:31 +04:00
|
|
|
$footnote->addText(htmlspecialchars('But you can only put footnote in section, not in header or footer.', ENT_COMPAT, 'UTF-8'));
|
2014-03-07 23:08:09 +01:00
|
|
|
|
2015-01-01 20:41:42 +04:00
|
|
|
$section->addText(
|
|
|
|
|
htmlspecialchars(
|
|
|
|
|
'You can also create the footnote directly from the section making it wrap in a paragraph '
|
2015-02-06 22:28:31 +04:00
|
|
|
. 'like the footnote below this paragraph. But is is best used from within a textrun.',
|
|
|
|
|
ENT_COMPAT,
|
|
|
|
|
'UTF-8'
|
2015-01-01 20:41:42 +04:00
|
|
|
)
|
|
|
|
|
);
|
2014-04-02 11:02:56 +07:00
|
|
|
$footnote = $section->addFootnote();
|
2015-02-06 22:28:31 +04:00
|
|
|
$footnote->addText(htmlspecialchars('The reference for this is wrapped in its own line', ENT_COMPAT, 'UTF-8'));
|
2014-03-07 23:08:09 +01: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
|
|
|
}
|