#483. Output escaping for OOXML.
This commit is contained in:
parent
4954f28012
commit
ec3c62b051
14
README.md
14
README.md
|
|
@ -93,11 +93,9 @@ $phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||||
$section = $phpWord->addSection();
|
$section = $phpWord->addSection();
|
||||||
// Adding Text element to the Section having font styled by default...
|
// Adding Text element to the Section having font styled by default...
|
||||||
$section->addText(
|
$section->addText(
|
||||||
htmlspecialchars(
|
|
||||||
'"Learn from yesterday, live for today, hope for tomorrow. '
|
'"Learn from yesterday, live for today, hope for tomorrow. '
|
||||||
. 'The important thing is not to stop questioning." '
|
. 'The important thing is not to stop questioning." '
|
||||||
. '(Albert Einstein)'
|
. '(Albert Einstein)'
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -109,11 +107,9 @@ $section->addText(
|
||||||
|
|
||||||
// Adding Text element with font customized inline...
|
// Adding Text element with font customized inline...
|
||||||
$section->addText(
|
$section->addText(
|
||||||
htmlspecialchars(
|
|
||||||
'"Great achievement is usually born of great sacrifice, '
|
'"Great achievement is usually born of great sacrifice, '
|
||||||
. 'and is never the result of selfishness." '
|
. 'and is never the result of selfishness." '
|
||||||
. '(Napoleon Hill)'
|
. '(Napoleon Hill)',
|
||||||
),
|
|
||||||
array('name' => 'Tahoma', 'size' => 10)
|
array('name' => 'Tahoma', 'size' => 10)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -124,11 +120,9 @@ $phpWord->addFontStyle(
|
||||||
array('name' => 'Tahoma', 'size' => 10, 'color' => '1B2232', 'bold' => true)
|
array('name' => 'Tahoma', 'size' => 10, 'color' => '1B2232', 'bold' => true)
|
||||||
);
|
);
|
||||||
$section->addText(
|
$section->addText(
|
||||||
htmlspecialchars(
|
|
||||||
'"The greatest accomplishment is not in never falling, '
|
'"The greatest accomplishment is not in never falling, '
|
||||||
. 'but in rising again after you fall." '
|
. 'but in rising again after you fall." '
|
||||||
. '(Vince Lombardi)'
|
. '(Vince Lombardi)',
|
||||||
),
|
|
||||||
$fontStyleName
|
$fontStyleName
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -137,9 +131,7 @@ $fontStyle = new \PhpOffice\PhpWord\Style\Font();
|
||||||
$fontStyle->setBold(true);
|
$fontStyle->setBold(true);
|
||||||
$fontStyle->setName('Tahoma');
|
$fontStyle->setName('Tahoma');
|
||||||
$fontStyle->setSize(13);
|
$fontStyle->setSize(13);
|
||||||
$myTextElement = $section->addText(
|
$myTextElement = $section->addText('"Believe you can and you\'re halfway there." (Theodor Roosevelt)');
|
||||||
htmlspecialchars('"Believe you can and you\'re halfway there." (Theodor Roosevelt)')
|
|
||||||
);
|
|
||||||
$myTextElement->setFontStyle($fontStyle);
|
$myTextElement->setFontStyle($fontStyle);
|
||||||
|
|
||||||
// Saving the document as OOXML file...
|
// Saving the document as OOXML file...
|
||||||
|
|
|
||||||
|
|
@ -24,13 +24,9 @@ folder <https://github.com/PHPOffice/PHPWord/tree/master/samples/>`__.
|
||||||
$section = $phpWord->addSection();
|
$section = $phpWord->addSection();
|
||||||
// Adding Text element to the Section having font styled by default...
|
// Adding Text element to the Section having font styled by default...
|
||||||
$section->addText(
|
$section->addText(
|
||||||
htmlspecialchars(
|
|
||||||
'"Learn from yesterday, live for today, hope for tomorrow. '
|
'"Learn from yesterday, live for today, hope for tomorrow. '
|
||||||
. 'The important thing is not to stop questioning." '
|
. 'The important thing is not to stop questioning." '
|
||||||
. '(Albert Einstein)',
|
. '(Albert Einstein)'
|
||||||
ENT_COMPAT,
|
|
||||||
'UTF-8'
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -42,13 +38,9 @@ folder <https://github.com/PHPOffice/PHPWord/tree/master/samples/>`__.
|
||||||
|
|
||||||
// Adding Text element with font customized inline...
|
// Adding Text element with font customized inline...
|
||||||
$section->addText(
|
$section->addText(
|
||||||
htmlspecialchars(
|
|
||||||
'"Great achievement is usually born of great sacrifice, '
|
'"Great achievement is usually born of great sacrifice, '
|
||||||
. 'and is never the result of selfishness." '
|
. 'and is never the result of selfishness." '
|
||||||
. '(Napoleon Hill)',
|
. '(Napoleon Hill)',
|
||||||
ENT_COMPAT,
|
|
||||||
'UTF-8'
|
|
||||||
),
|
|
||||||
array('name' => 'Tahoma', 'size' => 10)
|
array('name' => 'Tahoma', 'size' => 10)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -59,13 +51,9 @@ folder <https://github.com/PHPOffice/PHPWord/tree/master/samples/>`__.
|
||||||
array('name' => 'Tahoma', 'size' => 10, 'color' => '1B2232', 'bold' => true)
|
array('name' => 'Tahoma', 'size' => 10, 'color' => '1B2232', 'bold' => true)
|
||||||
);
|
);
|
||||||
$section->addText(
|
$section->addText(
|
||||||
htmlspecialchars(
|
|
||||||
'"The greatest accomplishment is not in never falling, '
|
'"The greatest accomplishment is not in never falling, '
|
||||||
. 'but in rising again after you fall." '
|
. 'but in rising again after you fall." '
|
||||||
. '(Vince Lombardi)',
|
. '(Vince Lombardi)',
|
||||||
ENT_COMPAT,
|
|
||||||
'UTF-8'
|
|
||||||
),
|
|
||||||
$fontStyleName
|
$fontStyleName
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -74,9 +62,7 @@ folder <https://github.com/PHPOffice/PHPWord/tree/master/samples/>`__.
|
||||||
$fontStyle->setBold(true);
|
$fontStyle->setBold(true);
|
||||||
$fontStyle->setName('Tahoma');
|
$fontStyle->setName('Tahoma');
|
||||||
$fontStyle->setSize(13);
|
$fontStyle->setSize(13);
|
||||||
$myTextElement = $section->addText(
|
$myTextElement = $section->addText('"Believe you can and you\'re halfway there." (Theodor Roosevelt)');
|
||||||
htmlspecialchars('"Believe you can and you\'re halfway there." (Theodor Roosevelt)', ENT_COMPAT, 'UTF-8')
|
|
||||||
);
|
|
||||||
$myTextElement->setFontStyle($fontStyle);
|
$myTextElement->setFontStyle($fontStyle);
|
||||||
|
|
||||||
// Saving the document as OOXML file...
|
// Saving the document as OOXML file...
|
||||||
|
|
@ -130,8 +116,22 @@ included with PHPWord.
|
||||||
|
|
||||||
\PhpOffice\PhpWord\Settings::setZipClass(\PhpOffice\PhpWord\Settings::PCLZIP);
|
\PhpOffice\PhpWord\Settings::setZipClass(\PhpOffice\PhpWord\Settings::PCLZIP);
|
||||||
|
|
||||||
|
Output escaping
|
||||||
|
~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
Writing documents of some formats, especially XML-based, requires correct output escaping.
|
||||||
|
Without it your document may become broken when you put special characters like ampersand, quotes, and others in it.
|
||||||
|
|
||||||
|
Escaping can be performed in two ways: outside of the library by a software developer and inside of the library by built-in mechanism.
|
||||||
|
By default, the built-in mechanism is disabled for backward compatibility with versions prior to v0.13.0.
|
||||||
|
To turn it on set ``outputEscapingEnabled`` option to ``true`` in your PHPWord configuration file or use the following instruction at runtime:
|
||||||
|
|
||||||
|
.. code-block:: php
|
||||||
|
|
||||||
|
\PhpOffice\PhpWord\Settings::setOutputEscapingEnabled(true);
|
||||||
|
|
||||||
Default font
|
Default font
|
||||||
------------
|
~~~~~~~~~~~~
|
||||||
|
|
||||||
By default, every text appears in Arial 10 point. You can alter the
|
By default, every text appears in Arial 10 point. You can alter the
|
||||||
default font by using the following two functions:
|
default font by using the following two functions:
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ zipClass = ZipArchive
|
||||||
pdfRendererName = DomPDF
|
pdfRendererName = DomPDF
|
||||||
pdfRendererPath =
|
pdfRendererPath =
|
||||||
; tempDir = "C:\PhpWordTemp"
|
; tempDir = "C:\PhpWordTemp"
|
||||||
|
outputEscapingEnabled = false
|
||||||
|
|
||||||
[Font]
|
[Font]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,24 +4,29 @@ include_once 'Sample_Header.php';
|
||||||
// New Word Document
|
// New Word Document
|
||||||
echo date('H:i:s') , ' Create new PhpWord object' , EOL;
|
echo date('H:i:s') , ' Create new PhpWord object' , EOL;
|
||||||
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||||
$phpWord->addFontStyle('rStyle', array('bold' => true, 'italic' => true, 'size' => 16, 'allCaps' => true, 'doubleStrikethrough' => true));
|
|
||||||
$phpWord->addParagraphStyle('pStyle', array('alignment' => \PhpOffice\PhpWord\SimpleType\Jc::CENTER, 'spaceAfter' => 100));
|
$fontStyleName = 'rStyle';
|
||||||
|
$phpWord->addFontStyle($fontStyleName, array('bold' => true, 'italic' => true, 'size' => 16, 'allCaps' => true, 'doubleStrikethrough' => true));
|
||||||
|
|
||||||
|
$paragraphStyleName = 'pStyle';
|
||||||
|
$phpWord->addParagraphStyle($paragraphStyleName, array('alignment' => \PhpOffice\PhpWord\SimpleType\Jc::CENTER, 'spaceAfter' => 100));
|
||||||
|
|
||||||
$phpWord->addTitleStyle(1, array('bold' => true), array('spaceAfter' => 240));
|
$phpWord->addTitleStyle(1, array('bold' => true), array('spaceAfter' => 240));
|
||||||
|
|
||||||
// New portrait section
|
// New portrait section
|
||||||
$section = $phpWord->addSection();
|
$section = $phpWord->addSection();
|
||||||
|
|
||||||
// Simple text
|
// Simple text
|
||||||
$section->addTitle(htmlspecialchars('Welcome to PhpWord', ENT_COMPAT, 'UTF-8'), 1);
|
$section->addTitle('Welcome to PhpWord', 1);
|
||||||
$section->addText(htmlspecialchars('Hello World!', ENT_COMPAT, 'UTF-8'));
|
$section->addText('Hello World!');
|
||||||
|
|
||||||
// Two text break
|
// Two text break
|
||||||
$section->addTextBreak(2);
|
$section->addTextBreak(2);
|
||||||
|
|
||||||
// Defined style
|
// Define styles
|
||||||
$section->addText(htmlspecialchars('I am styled by a font style definition.', ENT_COMPAT, 'UTF-8'), 'rStyle');
|
$section->addText('I am styled by a font style definition.', $fontStyleName);
|
||||||
$section->addText(htmlspecialchars('I am styled by a paragraph style definition.', ENT_COMPAT, 'UTF-8'), null, 'pStyle');
|
$section->addText('I am styled by a paragraph style definition.', null, $paragraphStyleName);
|
||||||
$section->addText(htmlspecialchars('I am styled by both font and paragraph style.', ENT_COMPAT, 'UTF-8'), 'rStyle', 'pStyle');
|
$section->addText('I am styled by both font and paragraph style.', $fontStyleName, $paragraphStyleName);
|
||||||
|
|
||||||
$section->addTextBreak();
|
$section->addTextBreak();
|
||||||
|
|
||||||
|
|
@ -30,39 +35,39 @@ $fontStyle['name'] = 'Times New Roman';
|
||||||
$fontStyle['size'] = 20;
|
$fontStyle['size'] = 20;
|
||||||
|
|
||||||
$textrun = $section->addTextRun();
|
$textrun = $section->addTextRun();
|
||||||
$textrun->addText(htmlspecialchars('I am inline styled ', ENT_COMPAT, 'UTF-8'), $fontStyle);
|
$textrun->addText('I am inline styled ', $fontStyle);
|
||||||
$textrun->addText(htmlspecialchars('with ', ENT_COMPAT, 'UTF-8'));
|
$textrun->addText('with ');
|
||||||
$textrun->addText(htmlspecialchars('color', ENT_COMPAT, 'UTF-8'), array('color' => '996699'));
|
$textrun->addText('color', array('color' => '996699'));
|
||||||
$textrun->addText(htmlspecialchars(', ', ENT_COMPAT, 'UTF-8'));
|
$textrun->addText(', ');
|
||||||
$textrun->addText(htmlspecialchars('bold', ENT_COMPAT, 'UTF-8'), array('bold' => true));
|
$textrun->addText('bold', array('bold' => true));
|
||||||
$textrun->addText(htmlspecialchars(', ', ENT_COMPAT, 'UTF-8'));
|
$textrun->addText(', ');
|
||||||
$textrun->addText(htmlspecialchars('italic', ENT_COMPAT, 'UTF-8'), array('italic' => true));
|
$textrun->addText('italic', array('italic' => true));
|
||||||
$textrun->addText(htmlspecialchars(', ', ENT_COMPAT, 'UTF-8'));
|
$textrun->addText(', ');
|
||||||
$textrun->addText(htmlspecialchars('underline', ENT_COMPAT, 'UTF-8'), array('underline' => 'dash'));
|
$textrun->addText('underline', array('underline' => 'dash'));
|
||||||
$textrun->addText(htmlspecialchars(', ', ENT_COMPAT, 'UTF-8'));
|
$textrun->addText(', ');
|
||||||
$textrun->addText(htmlspecialchars('strikethrough', ENT_COMPAT, 'UTF-8'), array('strikethrough' => true));
|
$textrun->addText('strikethrough', array('strikethrough' => true));
|
||||||
$textrun->addText(htmlspecialchars(', ', ENT_COMPAT, 'UTF-8'));
|
$textrun->addText(', ');
|
||||||
$textrun->addText(htmlspecialchars('doubleStrikethrough', ENT_COMPAT, 'UTF-8'), array('doubleStrikethrough' => true));
|
$textrun->addText('doubleStrikethrough', array('doubleStrikethrough' => true));
|
||||||
$textrun->addText(htmlspecialchars(', ', ENT_COMPAT, 'UTF-8'));
|
$textrun->addText(', ');
|
||||||
$textrun->addText(htmlspecialchars('superScript', ENT_COMPAT, 'UTF-8'), array('superScript' => true));
|
$textrun->addText('superScript', array('superScript' => true));
|
||||||
$textrun->addText(htmlspecialchars(', ', ENT_COMPAT, 'UTF-8'));
|
$textrun->addText(', ');
|
||||||
$textrun->addText(htmlspecialchars('subScript', ENT_COMPAT, 'UTF-8'), array('subScript' => true));
|
$textrun->addText('subScript', array('subScript' => true));
|
||||||
$textrun->addText(htmlspecialchars(', ', ENT_COMPAT, 'UTF-8'));
|
$textrun->addText(', ');
|
||||||
$textrun->addText(htmlspecialchars('smallCaps', ENT_COMPAT, 'UTF-8'), array('smallCaps' => true));
|
$textrun->addText('smallCaps', array('smallCaps' => true));
|
||||||
$textrun->addText(htmlspecialchars(', ', ENT_COMPAT, 'UTF-8'));
|
$textrun->addText(', ');
|
||||||
$textrun->addText(htmlspecialchars('allCaps', ENT_COMPAT, 'UTF-8'), array('allCaps' => true));
|
$textrun->addText('allCaps', array('allCaps' => true));
|
||||||
$textrun->addText(htmlspecialchars(', ', ENT_COMPAT, 'UTF-8'));
|
$textrun->addText(', ');
|
||||||
$textrun->addText(htmlspecialchars('fgColor', ENT_COMPAT, 'UTF-8'), array('fgColor' => 'yellow'));
|
$textrun->addText('fgColor', array('fgColor' => 'yellow'));
|
||||||
$textrun->addText(htmlspecialchars(', ', ENT_COMPAT, 'UTF-8'));
|
$textrun->addText(', ');
|
||||||
$textrun->addText(htmlspecialchars('scale', ENT_COMPAT, 'UTF-8'), array('scale' => 200));
|
$textrun->addText('scale', array('scale' => 200));
|
||||||
$textrun->addText(htmlspecialchars(', ', ENT_COMPAT, 'UTF-8'));
|
$textrun->addText(', ');
|
||||||
$textrun->addText(htmlspecialchars('spacing', ENT_COMPAT, 'UTF-8'), array('spacing' => 120));
|
$textrun->addText('spacing', array('spacing' => 120));
|
||||||
$textrun->addText(htmlspecialchars(', ', ENT_COMPAT, 'UTF-8'));
|
$textrun->addText(', ');
|
||||||
$textrun->addText(htmlspecialchars('kerning', ENT_COMPAT, 'UTF-8'), array('kerning' => 10));
|
$textrun->addText('kerning', array('kerning' => 10));
|
||||||
$textrun->addText(htmlspecialchars('. ', ENT_COMPAT, 'UTF-8'));
|
$textrun->addText('. ');
|
||||||
|
|
||||||
// Link
|
// Link
|
||||||
$section->addLink('https://github.com/PHPOffice/PHPWord', htmlspecialchars('PHPWord on GitHub', ENT_COMPAT, 'UTF-8'));
|
$section->addLink('https://github.com/PHPOffice/PHPWord', 'PHPWord on GitHub');
|
||||||
$section->addTextBreak();
|
$section->addTextBreak();
|
||||||
|
|
||||||
// Image
|
// Image
|
||||||
|
|
|
||||||
|
|
@ -5,9 +5,10 @@ include_once 'Sample_Header.php';
|
||||||
echo date('H:i:s'), ' Create new PhpWord object', EOL;
|
echo date('H:i:s'), ' Create new PhpWord object', EOL;
|
||||||
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||||
|
|
||||||
// Ads styles
|
// Define styles
|
||||||
|
$multipleTabsStyleName = 'multipleTab';
|
||||||
$phpWord->addParagraphStyle(
|
$phpWord->addParagraphStyle(
|
||||||
'multipleTab',
|
$multipleTabsStyleName,
|
||||||
array(
|
array(
|
||||||
'tabs' => array(
|
'tabs' => array(
|
||||||
new \PhpOffice\PhpWord\Style\Tab('left', 1550),
|
new \PhpOffice\PhpWord\Style\Tab('left', 1550),
|
||||||
|
|
@ -16,22 +17,20 @@ $phpWord->addParagraphStyle(
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
$phpWord->addParagraphStyle(
|
|
||||||
'rightTab',
|
$rightTabStyleName = 'rightTab';
|
||||||
array('tabs' => array(new \PhpOffice\PhpWord\Style\Tab('right', 9090)))
|
$phpWord->addParagraphStyle($rightTabStyleName, array('tabs' => array(new \PhpOffice\PhpWord\Style\Tab('right', 9090))));
|
||||||
);
|
|
||||||
$phpWord->addParagraphStyle(
|
$leftTabStyleName = 'centerTab';
|
||||||
'centerTab',
|
$phpWord->addParagraphStyle($leftTabStyleName, array('tabs' => array(new \PhpOffice\PhpWord\Style\Tab('center', 4680))));
|
||||||
array('tabs' => array(new \PhpOffice\PhpWord\Style\Tab('center', 4680)))
|
|
||||||
);
|
|
||||||
|
|
||||||
// New portrait section
|
// New portrait section
|
||||||
$section = $phpWord->addSection();
|
$section = $phpWord->addSection();
|
||||||
|
|
||||||
// Add listitem elements
|
// Add listitem elements
|
||||||
$section->addText(htmlspecialchars("Multiple Tabs:\tOne\tTwo\tThree", ENT_COMPAT, 'UTF-8'), null, 'multipleTab');
|
$section->addText("Multiple Tabs:\tOne\tTwo\tThree", null, $multipleTabsStyleName);
|
||||||
$section->addText(htmlspecialchars("Left Aligned\tRight Aligned", ENT_COMPAT, 'UTF-8'), null, 'rightTab');
|
$section->addText("Left Aligned\tRight Aligned", null, $rightTabStyleName);
|
||||||
$section->addText(htmlspecialchars("\tCenter Aligned", ENT_COMPAT, 'UTF-8'), null, 'centerTab');
|
$section->addText("\tCenter Aligned", null, $leftTabStyleName);
|
||||||
|
|
||||||
// Save file
|
// Save file
|
||||||
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
||||||
|
|
|
||||||
|
|
@ -7,17 +7,11 @@ $phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||||
|
|
||||||
// New portrait section
|
// New portrait section
|
||||||
$section = $phpWord->addSection(array('borderColor' => '00FF00', 'borderSize' => 12));
|
$section = $phpWord->addSection(array('borderColor' => '00FF00', 'borderSize' => 12));
|
||||||
$section->addText(htmlspecialchars('I am placed on a default section.', ENT_COMPAT, 'UTF-8'));
|
$section->addText('I am placed on a default section.');
|
||||||
|
|
||||||
// New landscape section
|
// New landscape section
|
||||||
$section = $phpWord->addSection(array('orientation' => 'landscape'));
|
$section = $phpWord->addSection(array('orientation' => 'landscape'));
|
||||||
$section->addText(
|
$section->addText('I am placed on a landscape section. Every page starting from this section will be landscape style.');
|
||||||
htmlspecialchars(
|
|
||||||
'I am placed on a landscape section. Every page starting from this section will be landscape style.',
|
|
||||||
ENT_COMPAT,
|
|
||||||
'UTF-8'
|
|
||||||
)
|
|
||||||
);
|
|
||||||
$section->addPageBreak();
|
$section->addPageBreak();
|
||||||
$section->addPageBreak();
|
$section->addPageBreak();
|
||||||
|
|
||||||
|
|
@ -25,7 +19,7 @@ $section->addPageBreak();
|
||||||
$section = $phpWord->addSection(
|
$section = $phpWord->addSection(
|
||||||
array('paperSize' => 'Folio', 'marginLeft' => 600, 'marginRight' => 600, 'marginTop' => 600, 'marginBottom' => 600)
|
array('paperSize' => 'Folio', 'marginLeft' => 600, 'marginRight' => 600, 'marginTop' => 600, 'marginBottom' => 600)
|
||||||
);
|
);
|
||||||
$section->addText(htmlspecialchars('This section uses other margins with folio papersize.', ENT_COMPAT, 'UTF-8'));
|
$section->addText('This section uses other margins with folio papersize.');
|
||||||
|
|
||||||
// New portrait section with Header & Footer
|
// New portrait section with Header & Footer
|
||||||
$section = $phpWord->addSection(
|
$section = $phpWord->addSection(
|
||||||
|
|
@ -38,9 +32,9 @@ $section = $phpWord->addSection(
|
||||||
'footerHeight' => 50,
|
'footerHeight' => 50,
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
$section->addText(htmlspecialchars('This section and we play with header/footer height.', ENT_COMPAT, 'UTF-8'));
|
$section->addText('This section and we play with header/footer height.');
|
||||||
$section->addHeader()->addText(htmlspecialchars('Header', ENT_COMPAT, 'UTF-8'));
|
$section->addHeader()->addText('Header');
|
||||||
$section->addFooter()->addText(htmlspecialchars('Footer', ENT_COMPAT, 'UTF-8'));
|
$section->addFooter()->addText('Footer');
|
||||||
|
|
||||||
// Save file
|
// Save file
|
||||||
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
||||||
|
|
|
||||||
|
|
@ -5,39 +5,39 @@ include_once 'Sample_Header.php';
|
||||||
echo date('H:i:s'), ' Create new PhpWord object', EOL;
|
echo date('H:i:s'), ' Create new PhpWord object', EOL;
|
||||||
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||||
|
|
||||||
// Ads styles
|
// Define styles
|
||||||
$phpWord->addParagraphStyle('pStyle', array('spacing' => 100));
|
$paragraphStyleName = 'pStyle';
|
||||||
$phpWord->addFontStyle('BoldText', array('bold' => true));
|
$phpWord->addParagraphStyle($paragraphStyleName, array('spacing' => 100));
|
||||||
$phpWord->addFontStyle('ColoredText', array('color' => 'FF8080', 'bgColor' => 'FFFFCC'));
|
|
||||||
$phpWord->addLinkStyle(
|
$boldFontStyleName = 'BoldText';
|
||||||
'NLink',
|
$phpWord->addFontStyle($boldFontStyleName, array('bold' => true));
|
||||||
array('color' => '0000FF', 'underline' => \PhpOffice\PhpWord\Style\Font::UNDERLINE_SINGLE)
|
|
||||||
);
|
$coloredFontStyleName = 'ColoredText';
|
||||||
|
$phpWord->addFontStyle($coloredFontStyleName, array('color' => 'FF8080', 'bgColor' => 'FFFFCC'));
|
||||||
|
|
||||||
|
$linkFontStyleName = 'NLink';
|
||||||
|
$phpWord->addLinkStyle($linkFontStyleName, array('color' => '0000FF', 'underline' => \PhpOffice\PhpWord\Style\Font::UNDERLINE_SINGLE));
|
||||||
|
|
||||||
// New portrait section
|
// New portrait section
|
||||||
$section = $phpWord->addSection();
|
$section = $phpWord->addSection();
|
||||||
|
|
||||||
// Add text run
|
// Add text run
|
||||||
$textrun = $section->addTextRun('pStyle');
|
$textrun = $section->addTextRun($paragraphStyleName);
|
||||||
|
$textrun->addText('Each textrun can contain native text, link elements or an image.');
|
||||||
$textrun->addText(htmlspecialchars('Each textrun can contain native text, link elements or an image.', ENT_COMPAT, 'UTF-8'));
|
$textrun->addText(' No break is placed after adding an element.', $boldFontStyleName);
|
||||||
$textrun->addText(htmlspecialchars(' No break is placed after adding an element.', ENT_COMPAT, 'UTF-8'), 'BoldText');
|
$textrun->addText(' Both ');
|
||||||
$textrun->addText(htmlspecialchars(' Both ', ENT_COMPAT, 'UTF-8'));
|
$textrun->addText('superscript', array('superScript' => true));
|
||||||
$textrun->addText(htmlspecialchars('superscript', ENT_COMPAT, 'UTF-8'), array('superScript' => true));
|
$textrun->addText(' and ');
|
||||||
$textrun->addText(htmlspecialchars(' and ', ENT_COMPAT, 'UTF-8'));
|
$textrun->addText('subscript', array('subScript' => true));
|
||||||
$textrun->addText(htmlspecialchars('subscript', ENT_COMPAT, 'UTF-8'), array('subScript' => true));
|
$textrun->addText(' are also available.');
|
||||||
$textrun->addText(htmlspecialchars(' are also available.', ENT_COMPAT, 'UTF-8'));
|
$textrun->addText(' All elements are placed inside a paragraph with the optionally given paragraph style.', $coloredFontStyleName);
|
||||||
$textrun->addText(
|
$textrun->addText(' Sample Link: ');
|
||||||
htmlspecialchars(' All elements are placed inside a paragraph with the optionally given p-Style.', ENT_COMPAT, 'UTF-8'),
|
$textrun->addLink('https://github.com/PHPOffice/PHPWord', 'PHPWord on GitHub', $linkFontStyleName);
|
||||||
'ColoredText'
|
$textrun->addText(' Sample Image: ');
|
||||||
);
|
|
||||||
$textrun->addText(htmlspecialchars(' Sample Link: ', ENT_COMPAT, 'UTF-8'));
|
|
||||||
$textrun->addLink('https://github.com/PHPOffice/PHPWord', htmlspecialchars('PHPWord on GitHub', ENT_COMPAT, 'UTF-8'), 'NLink');
|
|
||||||
$textrun->addText(htmlspecialchars(' Sample Image: ', ENT_COMPAT, 'UTF-8'));
|
|
||||||
$textrun->addImage('resources/_earth.jpg', array('width' => 18, 'height' => 18));
|
$textrun->addImage('resources/_earth.jpg', array('width' => 18, 'height' => 18));
|
||||||
$textrun->addText(htmlspecialchars(' Sample Object: ', ENT_COMPAT, 'UTF-8'));
|
$textrun->addText(' Sample Object: ');
|
||||||
$textrun->addObject('resources/_sheet.xls');
|
$textrun->addObject('resources/_sheet.xls');
|
||||||
$textrun->addText(htmlspecialchars(' Here is some more text. ', ENT_COMPAT, 'UTF-8'));
|
$textrun->addText(' Here is some more text. ');
|
||||||
|
|
||||||
// Save file
|
// Save file
|
||||||
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ $filler = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. '
|
||||||
|
|
||||||
// Normal
|
// Normal
|
||||||
$section = $phpWord->addSection();
|
$section = $phpWord->addSection();
|
||||||
$section->addText(htmlspecialchars("Normal paragraph. {$filler}", ENT_COMPAT, 'UTF-8'));
|
$section->addText("Normal paragraph. {$filler}");
|
||||||
|
|
||||||
// Two columns
|
// Two columns
|
||||||
$section = $phpWord->addSection(
|
$section = $phpWord->addSection(
|
||||||
|
|
@ -21,11 +21,11 @@ $section = $phpWord->addSection(
|
||||||
'breakType' => 'continuous',
|
'breakType' => 'continuous',
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
$section->addText(htmlspecialchars("Two columns, one inch (1440 twips) spacing. {$filler}", ENT_COMPAT, 'UTF-8'));
|
$section->addText("Two columns, one inch (1440 twips) spacing. {$filler}");
|
||||||
|
|
||||||
// Normal
|
// Normal
|
||||||
$section = $phpWord->addSection(array('breakType' => 'continuous'));
|
$section = $phpWord->addSection(array('breakType' => 'continuous'));
|
||||||
$section->addText(htmlspecialchars("Normal paragraph again. {$filler}", ENT_COMPAT, 'UTF-8'));
|
$section->addText("Normal paragraph again. {$filler}");
|
||||||
|
|
||||||
// Three columns
|
// Three columns
|
||||||
$section = $phpWord->addSection(
|
$section = $phpWord->addSection(
|
||||||
|
|
@ -35,11 +35,11 @@ $section = $phpWord->addSection(
|
||||||
'breakType' => 'continuous',
|
'breakType' => 'continuous',
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
$section->addText(htmlspecialchars("Three columns, half inch (720 twips) spacing. {$filler}", ENT_COMPAT, 'UTF-8'));
|
$section->addText("Three columns, half inch (720 twips) spacing. {$filler}");
|
||||||
|
|
||||||
// Normal
|
// Normal
|
||||||
$section = $phpWord->addSection(array('breakType' => 'continuous'));
|
$section = $phpWord->addSection(array('breakType' => 'continuous'));
|
||||||
$section->addText(htmlspecialchars('Normal paragraph again.', ENT_COMPAT, 'UTF-8'));
|
$section->addText("Normal paragraph again. {$filler}");
|
||||||
|
|
||||||
// Save file
|
// Save file
|
||||||
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
||||||
|
|
|
||||||
|
|
@ -6,46 +6,46 @@ echo date('H:i:s'), ' Create new PhpWord object', EOL;
|
||||||
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||||
\PhpOffice\PhpWord\Settings::setCompatibility(false);
|
\PhpOffice\PhpWord\Settings::setCompatibility(false);
|
||||||
|
|
||||||
|
// Define styles
|
||||||
|
$paragraphStyleName = 'pStyle';
|
||||||
|
$phpWord->addParagraphStyle($paragraphStyleName, array('spacing' => 100));
|
||||||
|
|
||||||
|
$boldFontStyleName = 'BoldText';
|
||||||
|
$phpWord->addFontStyle($boldFontStyleName, array('bold' => true));
|
||||||
|
|
||||||
|
$coloredFontStyleName = 'ColoredText';
|
||||||
|
$phpWord->addFontStyle($coloredFontStyleName, array('color' => 'FF8080', 'bgColor' => 'FFFFCC'));
|
||||||
|
|
||||||
|
$linkFontStyleName = 'NLink';
|
||||||
|
$phpWord->addLinkStyle($linkFontStyleName, array('color' => '0000FF', 'underline' => \PhpOffice\PhpWord\Style\Font::UNDERLINE_SINGLE));
|
||||||
|
|
||||||
// New portrait section
|
// New portrait section
|
||||||
$section = $phpWord->addSection();
|
$section = $phpWord->addSection();
|
||||||
|
|
||||||
// Add style definitions
|
|
||||||
$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)
|
|
||||||
);
|
|
||||||
|
|
||||||
// Add text elements
|
// Add text elements
|
||||||
$textrun = $section->addTextRun('pStyle');
|
$textrun = $section->addTextRun($paragraphStyleName);
|
||||||
$textrun->addText(htmlspecialchars('This is some lead text in a paragraph with a following footnote. ', ENT_COMPAT, 'UTF-8'), 'pStyle');
|
$textrun->addText('This is some lead text in a paragraph with a following footnote. ', $paragraphStyleName);
|
||||||
|
|
||||||
$footnote = $textrun->addFootnote();
|
$footnote = $textrun->addFootnote();
|
||||||
$footnote->addText(htmlspecialchars('Just like a textrun, a footnote can contain native texts. ', ENT_COMPAT, 'UTF-8'));
|
$footnote->addText('Just like a textrun, a footnote can contain native texts. ');
|
||||||
$footnote->addText(htmlspecialchars('No break is placed after adding an element. ', ENT_COMPAT, 'UTF-8'), 'BoldText');
|
$footnote->addText('No break is placed after adding an element. ', $boldFontStyleName);
|
||||||
$footnote->addText(htmlspecialchars('All elements are placed inside a paragraph. ', ENT_COMPAT, 'UTF-8'), 'ColoredText');
|
$footnote->addText('All elements are placed inside a paragraph. ', $coloredFontStyleName);
|
||||||
$footnote->addTextBreak();
|
$footnote->addTextBreak();
|
||||||
$footnote->addText(htmlspecialchars('But you can insert a manual text break like above, ', ENT_COMPAT, 'UTF-8'));
|
$footnote->addText('But you can insert a manual text break like above, ');
|
||||||
$footnote->addText(htmlspecialchars('links like ', ENT_COMPAT, 'UTF-8'));
|
$footnote->addText('links like ');
|
||||||
$footnote->addLink('https://github.com/PHPOffice/PHPWord', htmlspecialchars('PHPWord on GitHub', ENT_COMPAT, 'UTF-8'), 'NLink');
|
$footnote->addLink('https://github.com/PHPOffice/PHPWord', 'PHPWord on GitHub', $linkFontStyleName);
|
||||||
$footnote->addText(htmlspecialchars(', image like ', ENT_COMPAT, 'UTF-8'));
|
$footnote->addText(', image like ');
|
||||||
$footnote->addImage('resources/_earth.jpg', array('width' => 18, 'height' => 18));
|
$footnote->addImage('resources/_earth.jpg', array('width' => 18, 'height' => 18));
|
||||||
$footnote->addText(htmlspecialchars(', or object like ', ENT_COMPAT, 'UTF-8'));
|
$footnote->addText(', or object like ');
|
||||||
$footnote->addObject('resources/_sheet.xls');
|
$footnote->addObject('resources/_sheet.xls');
|
||||||
$footnote->addText(htmlspecialchars('But you can only put footnote in section, not in header or footer.', ENT_COMPAT, 'UTF-8'));
|
$footnote->addText('But you can only put footnote in section, not in header or footer.');
|
||||||
|
|
||||||
$section->addText(
|
$section->addText(
|
||||||
htmlspecialchars(
|
|
||||||
'You can also create the footnote directly from the section making it wrap in a paragraph '
|
'You can also create the footnote directly from the section making it wrap in a paragraph '
|
||||||
. 'like the footnote below this paragraph. But is is best used from within a textrun.',
|
. 'like the footnote below this paragraph. But is is best used from within a textrun.'
|
||||||
ENT_COMPAT,
|
|
||||||
'UTF-8'
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
$footnote = $section->addFootnote();
|
$footnote = $section->addFootnote();
|
||||||
$footnote->addText(htmlspecialchars('The reference for this is wrapped in its own line', ENT_COMPAT, 'UTF-8'));
|
$footnote->addText('The reference for this is wrapped in its own line');
|
||||||
|
|
||||||
// Save file
|
// Save file
|
||||||
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
||||||
|
|
|
||||||
|
|
@ -6,52 +6,52 @@ echo date('H:i:s'), ' Creating new TemplateProcessor instance...', EOL;
|
||||||
$templateProcessor = new \PhpOffice\PhpWord\TemplateProcessor('resources/Sample_07_TemplateCloneRow.docx');
|
$templateProcessor = new \PhpOffice\PhpWord\TemplateProcessor('resources/Sample_07_TemplateCloneRow.docx');
|
||||||
|
|
||||||
// Variables on different parts of document
|
// Variables on different parts of document
|
||||||
$templateProcessor->setValue('weekday', htmlspecialchars(date('l'), ENT_COMPAT, 'UTF-8')); // On section/content
|
$templateProcessor->setValue('weekday', date('l')); // On section/content
|
||||||
$templateProcessor->setValue('time', htmlspecialchars(date('H:i'), ENT_COMPAT, 'UTF-8')); // On footer
|
$templateProcessor->setValue('time', date('H:i')); // On footer
|
||||||
$templateProcessor->setValue('serverName', htmlspecialchars(realpath(__DIR__), ENT_COMPAT, 'UTF-8')); // On header
|
$templateProcessor->setValue('serverName', realpath(__DIR__)); // On header
|
||||||
|
|
||||||
// Simple table
|
// Simple table
|
||||||
$templateProcessor->cloneRow('rowValue', 10);
|
$templateProcessor->cloneRow('rowValue', 10);
|
||||||
|
|
||||||
$templateProcessor->setValue('rowValue#1', htmlspecialchars('Sun', ENT_COMPAT, 'UTF-8'));
|
$templateProcessor->setValue('rowValue#1', 'Sun');
|
||||||
$templateProcessor->setValue('rowValue#2', htmlspecialchars('Mercury', ENT_COMPAT, 'UTF-8'));
|
$templateProcessor->setValue('rowValue#2', 'Mercury');
|
||||||
$templateProcessor->setValue('rowValue#3', htmlspecialchars('Venus', ENT_COMPAT, 'UTF-8'));
|
$templateProcessor->setValue('rowValue#3', 'Venus');
|
||||||
$templateProcessor->setValue('rowValue#4', htmlspecialchars('Earth', ENT_COMPAT, 'UTF-8'));
|
$templateProcessor->setValue('rowValue#4', 'Earth');
|
||||||
$templateProcessor->setValue('rowValue#5', htmlspecialchars('Mars', ENT_COMPAT, 'UTF-8'));
|
$templateProcessor->setValue('rowValue#5', 'Mars');
|
||||||
$templateProcessor->setValue('rowValue#6', htmlspecialchars('Jupiter', ENT_COMPAT, 'UTF-8'));
|
$templateProcessor->setValue('rowValue#6', 'Jupiter');
|
||||||
$templateProcessor->setValue('rowValue#7', htmlspecialchars('Saturn', ENT_COMPAT, 'UTF-8'));
|
$templateProcessor->setValue('rowValue#7', 'Saturn');
|
||||||
$templateProcessor->setValue('rowValue#8', htmlspecialchars('Uranus', ENT_COMPAT, 'UTF-8'));
|
$templateProcessor->setValue('rowValue#8', 'Uranus');
|
||||||
$templateProcessor->setValue('rowValue#9', htmlspecialchars('Neptun', ENT_COMPAT, 'UTF-8'));
|
$templateProcessor->setValue('rowValue#9', 'Neptun');
|
||||||
$templateProcessor->setValue('rowValue#10', htmlspecialchars('Pluto', ENT_COMPAT, 'UTF-8'));
|
$templateProcessor->setValue('rowValue#10', 'Pluto');
|
||||||
|
|
||||||
$templateProcessor->setValue('rowNumber#1', htmlspecialchars('1', ENT_COMPAT, 'UTF-8'));
|
$templateProcessor->setValue('rowNumber#1', '1');
|
||||||
$templateProcessor->setValue('rowNumber#2', htmlspecialchars('2', ENT_COMPAT, 'UTF-8'));
|
$templateProcessor->setValue('rowNumber#2', '2');
|
||||||
$templateProcessor->setValue('rowNumber#3', htmlspecialchars('3', ENT_COMPAT, 'UTF-8'));
|
$templateProcessor->setValue('rowNumber#3', '3');
|
||||||
$templateProcessor->setValue('rowNumber#4', htmlspecialchars('4', ENT_COMPAT, 'UTF-8'));
|
$templateProcessor->setValue('rowNumber#4', '4');
|
||||||
$templateProcessor->setValue('rowNumber#5', htmlspecialchars('5', ENT_COMPAT, 'UTF-8'));
|
$templateProcessor->setValue('rowNumber#5', '5');
|
||||||
$templateProcessor->setValue('rowNumber#6', htmlspecialchars('6', ENT_COMPAT, 'UTF-8'));
|
$templateProcessor->setValue('rowNumber#6', '6');
|
||||||
$templateProcessor->setValue('rowNumber#7', htmlspecialchars('7', ENT_COMPAT, 'UTF-8'));
|
$templateProcessor->setValue('rowNumber#7', '7');
|
||||||
$templateProcessor->setValue('rowNumber#8', htmlspecialchars('8', ENT_COMPAT, 'UTF-8'));
|
$templateProcessor->setValue('rowNumber#8', '8');
|
||||||
$templateProcessor->setValue('rowNumber#9', htmlspecialchars('9', ENT_COMPAT, 'UTF-8'));
|
$templateProcessor->setValue('rowNumber#9', '9');
|
||||||
$templateProcessor->setValue('rowNumber#10', htmlspecialchars('10', ENT_COMPAT, 'UTF-8'));
|
$templateProcessor->setValue('rowNumber#10', '10');
|
||||||
|
|
||||||
// Table with a spanned cell
|
// Table with a spanned cell
|
||||||
$templateProcessor->cloneRow('userId', 3);
|
$templateProcessor->cloneRow('userId', 3);
|
||||||
|
|
||||||
$templateProcessor->setValue('userId#1', htmlspecialchars('1', ENT_COMPAT, 'UTF-8'));
|
$templateProcessor->setValue('userId#1', '1');
|
||||||
$templateProcessor->setValue('userFirstName#1', htmlspecialchars('James', ENT_COMPAT, 'UTF-8'));
|
$templateProcessor->setValue('userFirstName#1', 'James');
|
||||||
$templateProcessor->setValue('userName#1', htmlspecialchars('Taylor', ENT_COMPAT, 'UTF-8'));
|
$templateProcessor->setValue('userName#1', 'Taylor');
|
||||||
$templateProcessor->setValue('userPhone#1', htmlspecialchars('+1 428 889 773', ENT_COMPAT, 'UTF-8'));
|
$templateProcessor->setValue('userPhone#1', '+1 428 889 773');
|
||||||
|
|
||||||
$templateProcessor->setValue('userId#2', htmlspecialchars('2', ENT_COMPAT, 'UTF-8'));
|
$templateProcessor->setValue('userId#2', '2');
|
||||||
$templateProcessor->setValue('userFirstName#2', htmlspecialchars('Robert', ENT_COMPAT, 'UTF-8'));
|
$templateProcessor->setValue('userFirstName#2', 'Robert');
|
||||||
$templateProcessor->setValue('userName#2', htmlspecialchars('Bell', ENT_COMPAT, 'UTF-8'));
|
$templateProcessor->setValue('userName#2', 'Bell');
|
||||||
$templateProcessor->setValue('userPhone#2', htmlspecialchars('+1 428 889 774', ENT_COMPAT, 'UTF-8'));
|
$templateProcessor->setValue('userPhone#2', '+1 428 889 774');
|
||||||
|
|
||||||
$templateProcessor->setValue('userId#3', htmlspecialchars('3', ENT_COMPAT, 'UTF-8'));
|
$templateProcessor->setValue('userId#3', '3');
|
||||||
$templateProcessor->setValue('userFirstName#3', htmlspecialchars('Michael', ENT_COMPAT, 'UTF-8'));
|
$templateProcessor->setValue('userFirstName#3', 'Michael');
|
||||||
$templateProcessor->setValue('userName#3', htmlspecialchars('Ray', ENT_COMPAT, 'UTF-8'));
|
$templateProcessor->setValue('userName#3', 'Ray');
|
||||||
$templateProcessor->setValue('userPhone#3', htmlspecialchars('+1 428 889 775', ENT_COMPAT, 'UTF-8'));
|
$templateProcessor->setValue('userPhone#3', '+1 428 889 775');
|
||||||
|
|
||||||
echo date('H:i:s'), ' Saving the result document...', EOL;
|
echo date('H:i:s'), ' Saving the result document...', EOL;
|
||||||
$templateProcessor->saveAs('results/Sample_07_TemplateCloneRow.docx');
|
$templateProcessor->saveAs('results/Sample_07_TemplateCloneRow.docx');
|
||||||
|
|
|
||||||
|
|
@ -12,72 +12,52 @@ $phpWord->setDefaultParagraphStyle(
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
// Sample
|
// New section
|
||||||
$section = $phpWord->addSection();
|
$section = $phpWord->addSection();
|
||||||
|
|
||||||
$section->addText(
|
$section->addText(
|
||||||
htmlspecialchars(
|
|
||||||
'Below are the samples on how to control your paragraph '
|
'Below are the samples on how to control your paragraph '
|
||||||
. 'pagination. See "Line and Page Break" tab on paragraph properties '
|
. 'pagination. See "Line and Page Break" tab on paragraph properties '
|
||||||
. 'window to see the attribute set by these controls.',
|
. 'window to see the attribute set by these controls.',
|
||||||
ENT_COMPAT,
|
|
||||||
'UTF-8'
|
|
||||||
),
|
|
||||||
array('bold' => true),
|
array('bold' => true),
|
||||||
array('space' => array('before' => 360, 'after' => 480))
|
array('space' => array('before' => 360, 'after' => 480))
|
||||||
);
|
);
|
||||||
|
|
||||||
$section->addText(
|
$section->addText(
|
||||||
htmlspecialchars(
|
|
||||||
'Paragraph with widowControl = false (default: true). '
|
'Paragraph with widowControl = false (default: true). '
|
||||||
. 'A "widow" is the last line of a paragraph printed by itself at the top '
|
. 'A "widow" is the last line of a paragraph printed by itself at the top '
|
||||||
. 'of a page. An "orphan" is the first line of a paragraph printed by '
|
. 'of a page. An "orphan" is the first line of a paragraph printed by '
|
||||||
. 'itself at the bottom of a page. Set this option to "false" if you want '
|
. 'itself at the bottom of a page. Set this option to "false" if you want '
|
||||||
. 'to disable this automatic control.',
|
. 'to disable this automatic control.',
|
||||||
ENT_COMPAT,
|
|
||||||
'UTF-8'
|
|
||||||
),
|
|
||||||
null,
|
null,
|
||||||
array('widowControl' => false, 'indentation' => array('left' => 240, 'right' => 120))
|
array('widowControl' => false, 'indentation' => array('left' => 240, 'right' => 120))
|
||||||
);
|
);
|
||||||
|
|
||||||
$section->addText(
|
$section->addText(
|
||||||
htmlspecialchars(
|
|
||||||
'Paragraph with keepNext = true (default: false). '
|
'Paragraph with keepNext = true (default: false). '
|
||||||
. '"Keep with next" is used to prevent Word from inserting automatic page '
|
. '"Keep with next" is used to prevent Word from inserting automatic page '
|
||||||
. 'breaks between paragraphs. Set this option to "true" if you do not want '
|
. 'breaks between paragraphs. Set this option to "true" if you do not want '
|
||||||
. 'your paragraph to be separated with the next paragraph.',
|
. 'your paragraph to be separated with the next paragraph.',
|
||||||
ENT_COMPAT,
|
|
||||||
'UTF-8'
|
|
||||||
),
|
|
||||||
null,
|
null,
|
||||||
array('keepNext' => true, 'indentation' => array('firstLine' => 240))
|
array('keepNext' => true, 'indentation' => array('firstLine' => 240))
|
||||||
);
|
);
|
||||||
|
|
||||||
$section->addText(
|
$section->addText(
|
||||||
htmlspecialchars(
|
|
||||||
'Paragraph with keepLines = true (default: false). '
|
'Paragraph with keepLines = true (default: false). '
|
||||||
. '"Keep lines together" will prevent Word from inserting an automatic page '
|
. '"Keep lines together" will prevent Word from inserting an automatic page '
|
||||||
. 'break within a paragraph. Set this option to "true" if you do not want '
|
. 'break within a paragraph. Set this option to "true" if you do not want '
|
||||||
. 'all lines of your paragraph to be in the same page.',
|
. 'all lines of your paragraph to be in the same page.',
|
||||||
ENT_COMPAT,
|
|
||||||
'UTF-8'
|
|
||||||
),
|
|
||||||
null,
|
null,
|
||||||
array('keepLines' => true, 'indentation' => array('left' => 240, 'hanging' => 240))
|
array('keepLines' => true, 'indentation' => array('left' => 240, 'hanging' => 240))
|
||||||
);
|
);
|
||||||
|
|
||||||
$section->addText(htmlspecialchars('Keep scrolling. More below.', ENT_COMPAT, 'UTF-8'));
|
$section->addText('Keep scrolling. More below.');
|
||||||
|
|
||||||
$section->addText(
|
$section->addText(
|
||||||
htmlspecialchars(
|
|
||||||
'Paragraph with pageBreakBefore = true (default: false). '
|
'Paragraph with pageBreakBefore = true (default: false). '
|
||||||
. 'Different with all other control above, "page break before" separates '
|
. 'Different with all other control above, "page break before" separates '
|
||||||
. 'your paragraph into the next page. This option is most useful for '
|
. 'your paragraph into the next page. This option is most useful for '
|
||||||
. 'heading styles.',
|
. 'heading styles.',
|
||||||
ENT_COMPAT,
|
|
||||||
'UTF-8'
|
|
||||||
),
|
|
||||||
null,
|
null,
|
||||||
array('pageBreakBefore' => true)
|
array('pageBreakBefore' => true)
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -11,42 +11,43 @@ $header = array('size' => 16, 'bold' => true);
|
||||||
|
|
||||||
$rows = 10;
|
$rows = 10;
|
||||||
$cols = 5;
|
$cols = 5;
|
||||||
$section->addText(htmlspecialchars('Basic table', ENT_COMPAT, 'UTF-8'), $header);
|
$section->addText('Basic table', $header);
|
||||||
|
|
||||||
$table = $section->addTable();
|
$table = $section->addTable();
|
||||||
for ($r = 1; $r <= 8; $r++) {
|
for ($r = 1; $r <= 8; $r++) {
|
||||||
$table->addRow();
|
$table->addRow();
|
||||||
for ($c = 1; $c <= 5; $c++) {
|
for ($c = 1; $c <= 5; $c++) {
|
||||||
$table->addCell(1750)->addText(htmlspecialchars("Row {$r}, Cell {$c}", ENT_COMPAT, 'UTF-8'));
|
$table->addCell(1750)->addText("Row {$r}, Cell {$c}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. Advanced table
|
// 2. Advanced table
|
||||||
|
|
||||||
$section->addTextBreak(1);
|
$section->addTextBreak(1);
|
||||||
$section->addText(htmlspecialchars('Fancy table', ENT_COMPAT, 'UTF-8'), $header);
|
$section->addText('Fancy table', $header);
|
||||||
|
|
||||||
$styleTable = array('borderSize' => 6, 'borderColor' => '006699', 'cellMargin' => 80, 'alignment' => \PhpOffice\PhpWord\SimpleType\JcTable::CENTER);
|
$fancyTableStyleName = 'Fancy Table';
|
||||||
$styleFirstRow = array('borderBottomSize' => 18, 'borderBottomColor' => '0000FF', 'bgColor' => '66BBFF');
|
$fancyTableStyle = array('borderSize' => 6, 'borderColor' => '006699', 'cellMargin' => 80, 'alignment' => \PhpOffice\PhpWord\SimpleType\JcTable::CENTER);
|
||||||
$styleCell = array('valign' => 'center');
|
$fancyTableFirstRowStyle = array('borderBottomSize' => 18, 'borderBottomColor' => '0000FF', 'bgColor' => '66BBFF');
|
||||||
$styleCellBTLR = array('valign' => 'center', 'textDirection' => \PhpOffice\PhpWord\Style\Cell::TEXT_DIR_BTLR);
|
$fancyTableCellStyle = array('valign' => 'center');
|
||||||
$fontStyle = array('bold' => true);
|
$fancyTableCellBtlrStyle = array('valign' => 'center', 'textDirection' => \PhpOffice\PhpWord\Style\Cell::TEXT_DIR_BTLR);
|
||||||
$phpWord->addTableStyle('Fancy Table', $styleTable, $styleFirstRow);
|
$fancyTableFontStyle = array('bold' => true);
|
||||||
$table = $section->addTable('Fancy Table');
|
$phpWord->addTableStyle($fancyTableStyleName, $fancyTableStyle, $fancyTableFirstRowStyle);
|
||||||
|
$table = $section->addTable($fancyTableStyleName);
|
||||||
$table->addRow(900);
|
$table->addRow(900);
|
||||||
$table->addCell(2000, $styleCell)->addText(htmlspecialchars('Row 1', ENT_COMPAT, 'UTF-8'), $fontStyle);
|
$table->addCell(2000, $fancyTableCellStyle)->addText('Row 1', $fancyTableFontStyle);
|
||||||
$table->addCell(2000, $styleCell)->addText(htmlspecialchars('Row 2', ENT_COMPAT, 'UTF-8'), $fontStyle);
|
$table->addCell(2000, $fancyTableCellStyle)->addText('Row 2', $fancyTableFontStyle);
|
||||||
$table->addCell(2000, $styleCell)->addText(htmlspecialchars('Row 3', ENT_COMPAT, 'UTF-8'), $fontStyle);
|
$table->addCell(2000, $fancyTableCellStyle)->addText('Row 3', $fancyTableFontStyle);
|
||||||
$table->addCell(2000, $styleCell)->addText(htmlspecialchars('Row 4', ENT_COMPAT, 'UTF-8'), $fontStyle);
|
$table->addCell(2000, $fancyTableCellStyle)->addText('Row 4', $fancyTableFontStyle);
|
||||||
$table->addCell(500, $styleCellBTLR)->addText(htmlspecialchars('Row 5', ENT_COMPAT, 'UTF-8'), $fontStyle);
|
$table->addCell(500, $fancyTableCellBtlrStyle)->addText('Row 5', $fancyTableFontStyle);
|
||||||
for ($i = 1; $i <= 8; $i++) {
|
for ($i = 1; $i <= 8; $i++) {
|
||||||
$table->addRow();
|
$table->addRow();
|
||||||
$table->addCell(2000)->addText(htmlspecialchars("Cell {$i}", ENT_COMPAT, 'UTF-8'));
|
$table->addCell(2000)->addText("Cell {$i}");
|
||||||
$table->addCell(2000)->addText(htmlspecialchars("Cell {$i}", ENT_COMPAT, 'UTF-8'));
|
$table->addCell(2000)->addText("Cell {$i}");
|
||||||
$table->addCell(2000)->addText(htmlspecialchars("Cell {$i}", ENT_COMPAT, 'UTF-8'));
|
$table->addCell(2000)->addText("Cell {$i}");
|
||||||
$table->addCell(2000)->addText(htmlspecialchars("Cell {$i}", ENT_COMPAT, 'UTF-8'));
|
$table->addCell(2000)->addText("Cell {$i}");
|
||||||
$text = (0== $i % 2) ? 'X' : '';
|
$text = (0== $i % 2) ? 'X' : '';
|
||||||
$table->addCell(500)->addText(htmlspecialchars($text, ENT_COMPAT, 'UTF-8'));
|
$table->addCell(500)->addText($text);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -59,36 +60,37 @@ for ($i = 1; $i <= 8; $i++) {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$section->addPageBreak();
|
$section->addPageBreak();
|
||||||
$section->addText(htmlspecialchars('Table with colspan and rowspan', ENT_COMPAT, 'UTF-8'), $header);
|
$section->addText('Table with colspan and rowspan', $header);
|
||||||
|
|
||||||
$styleTable = array('borderSize' => 6, 'borderColor' => '999999');
|
$fancyTableStyle = array('borderSize' => 6, 'borderColor' => '999999');
|
||||||
$cellRowSpan = array('vMerge' => 'restart', 'valign' => 'center', 'bgColor' => 'FFFF00');
|
$cellRowSpan = array('vMerge' => 'restart', 'valign' => 'center', 'bgColor' => 'FFFF00');
|
||||||
$cellRowContinue = array('vMerge' => 'continue');
|
$cellRowContinue = array('vMerge' => 'continue');
|
||||||
$cellColSpan = array('gridSpan' => 2, 'valign' => 'center');
|
$cellColSpan = array('gridSpan' => 2, 'valign' => 'center');
|
||||||
$cellHCentered = array('alignment' => \PhpOffice\PhpWord\SimpleType\Jc::CENTER);
|
$cellHCentered = array('alignment' => \PhpOffice\PhpWord\SimpleType\Jc::CENTER);
|
||||||
$cellVCentered = array('valign' => 'center');
|
$cellVCentered = array('valign' => 'center');
|
||||||
|
|
||||||
$phpWord->addTableStyle('Colspan Rowspan', $styleTable);
|
$spanTableStyleName = 'Colspan Rowspan';
|
||||||
$table = $section->addTable('Colspan Rowspan');
|
$phpWord->addTableStyle($spanTableStyleName, $fancyTableStyle);
|
||||||
|
$table = $section->addTable($spanTableStyleName);
|
||||||
|
|
||||||
$table->addRow();
|
$table->addRow();
|
||||||
|
|
||||||
$cell1 = $table->addCell(2000, $cellRowSpan);
|
$cell1 = $table->addCell(2000, $cellRowSpan);
|
||||||
$textrun1 = $cell1->addTextRun($cellHCentered);
|
$textrun1 = $cell1->addTextRun($cellHCentered);
|
||||||
$textrun1->addText(htmlspecialchars('A', ENT_COMPAT, 'UTF-8'));
|
$textrun1->addText('A');
|
||||||
$textrun1->addFootnote()->addText(htmlspecialchars('Row span', ENT_COMPAT, 'UTF-8'));
|
$textrun1->addFootnote()->addText('Row span');
|
||||||
|
|
||||||
$cell2 = $table->addCell(4000, $cellColSpan);
|
$cell2 = $table->addCell(4000, $cellColSpan);
|
||||||
$textrun2 = $cell2->addTextRun($cellHCentered);
|
$textrun2 = $cell2->addTextRun($cellHCentered);
|
||||||
$textrun2->addText(htmlspecialchars('B', ENT_COMPAT, 'UTF-8'));
|
$textrun2->addText('B');
|
||||||
$textrun2->addFootnote()->addText(htmlspecialchars('Colspan span', ENT_COMPAT, 'UTF-8'));
|
$textrun2->addFootnote()->addText('Column span');
|
||||||
|
|
||||||
$table->addCell(2000, $cellRowSpan)->addText(htmlspecialchars('E', ENT_COMPAT, 'UTF-8'), null, $cellHCentered);
|
$table->addCell(2000, $cellRowSpan)->addText('E', null, $cellHCentered);
|
||||||
|
|
||||||
$table->addRow();
|
$table->addRow();
|
||||||
$table->addCell(null, $cellRowContinue);
|
$table->addCell(null, $cellRowContinue);
|
||||||
$table->addCell(2000, $cellVCentered)->addText(htmlspecialchars('C', ENT_COMPAT, 'UTF-8'), null, $cellHCentered);
|
$table->addCell(2000, $cellVCentered)->addText('C', null, $cellHCentered);
|
||||||
$table->addCell(2000, $cellVCentered)->addText(htmlspecialchars('D', ENT_COMPAT, 'UTF-8'), null, $cellHCentered);
|
$table->addCell(2000, $cellVCentered)->addText('D', null, $cellHCentered);
|
||||||
$table->addCell(null, $cellRowContinue);
|
$table->addCell(null, $cellRowContinue);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -103,7 +105,7 @@ $table->addCell(null, $cellRowContinue);
|
||||||
* @see https://github.com/PHPOffice/PHPWord/issues/806
|
* @see https://github.com/PHPOffice/PHPWord/issues/806
|
||||||
*/
|
*/
|
||||||
$section->addPageBreak();
|
$section->addPageBreak();
|
||||||
$section->addText(htmlspecialchars('Table with colspan and rowspan', ENT_COMPAT, 'UTF-8'), $header);
|
$section->addText('Table with colspan and rowspan', $header);
|
||||||
|
|
||||||
$styleTable = ['borderSize' => 6, 'borderColor' => '999999'];
|
$styleTable = ['borderSize' => 6, 'borderColor' => '999999'];
|
||||||
$phpWord->addTableStyle('Colspan Rowspan', $styleTable);
|
$phpWord->addTableStyle('Colspan Rowspan', $styleTable);
|
||||||
|
|
@ -128,13 +130,13 @@ $row->addCell()->addText('3');
|
||||||
// 5. Nested table
|
// 5. Nested table
|
||||||
|
|
||||||
$section->addTextBreak(2);
|
$section->addTextBreak(2);
|
||||||
$section->addText(htmlspecialchars('Nested table in a centered and 50% width table.', ENT_COMPAT, 'UTF-8'), $header);
|
$section->addText('Nested table in a centered and 50% width table.', $header);
|
||||||
|
|
||||||
$table = $section->addTable(array('width' => 50 * 50, 'unit' => 'pct', 'alignment' => \PhpOffice\PhpWord\SimpleType\JcTable::CENTER));
|
$table = $section->addTable(array('width' => 50 * 50, 'unit' => 'pct', 'alignment' => \PhpOffice\PhpWord\SimpleType\JcTable::CENTER));
|
||||||
$cell = $table->addRow()->addCell();
|
$cell = $table->addRow()->addCell();
|
||||||
$cell->addText(htmlspecialchars('This cell contains nested table.', ENT_COMPAT, 'UTF-8'));
|
$cell->addText('This cell contains nested table.');
|
||||||
$innerCell = $cell->addTable(array('alignment' => \PhpOffice\PhpWord\SimpleType\JcTable::CENTER))->addRow()->addCell();
|
$innerCell = $cell->addTable(array('alignment' => \PhpOffice\PhpWord\SimpleType\JcTable::CENTER))->addRow()->addCell();
|
||||||
$innerCell->addText(htmlspecialchars('Inside nested table', ENT_COMPAT, 'UTF-8'));
|
$innerCell->addText('Inside nested table');
|
||||||
|
|
||||||
// Save file
|
// Save file
|
||||||
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ $phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||||
$section = $phpWord->addSection();
|
$section = $phpWord->addSection();
|
||||||
$header = array('size' => 16, 'bold' => true);
|
$header = array('size' => 16, 'bold' => true);
|
||||||
//1.Use EastAisa FontStyle
|
//1.Use EastAisa FontStyle
|
||||||
$section->addText(htmlspecialchars('中文楷体样式测试', ENT_COMPAT, 'UTF-8'), array('name' => '楷体', 'size' => 16, 'color' => '1B2232'));
|
$section->addText('中文楷体样式测试', array('name' => '楷体', 'size' => 16, 'color' => '1B2232'));
|
||||||
|
|
||||||
// Save file
|
// Save file
|
||||||
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
||||||
|
|
|
||||||
|
|
@ -15,47 +15,47 @@ $table = $header->addTable();
|
||||||
$table->addRow();
|
$table->addRow();
|
||||||
$cell = $table->addCell(4500);
|
$cell = $table->addCell(4500);
|
||||||
$textrun = $cell->addTextRun();
|
$textrun = $cell->addTextRun();
|
||||||
$textrun->addText(htmlspecialchars('This is the header with ', ENT_COMPAT, 'UTF-8'));
|
$textrun->addText('This is the header with ');
|
||||||
$textrun->addLink('https://github.com/PHPOffice/PHPWord', htmlspecialchars('PHPWord on GitHub', ENT_COMPAT, 'UTF-8'));
|
$textrun->addLink('https://github.com/PHPOffice/PHPWord', 'PHPWord on GitHub');
|
||||||
$table->addCell(4500)->addImage('resources/PhpWord.png', array('width' => 80, 'height' => 80, 'alignment' => \PhpOffice\PhpWord\SimpleType\Jc::END));
|
$table->addCell(4500)->addImage('resources/PhpWord.png', array('width' => 80, 'height' => 80, 'alignment' => \PhpOffice\PhpWord\SimpleType\Jc::END));
|
||||||
|
|
||||||
// Add header for all other pages
|
// Add header for all other pages
|
||||||
$subsequent = $section->addHeader();
|
$subsequent = $section->addHeader();
|
||||||
$subsequent->addText(htmlspecialchars('Subsequent pages in Section 1 will Have this!', ENT_COMPAT, 'UTF-8'));
|
$subsequent->addText('Subsequent pages in Section 1 will Have this!');
|
||||||
$subsequent->addImage('resources/_mars.jpg', array('width' => 80, 'height' => 80));
|
$subsequent->addImage('resources/_mars.jpg', array('width' => 80, 'height' => 80));
|
||||||
|
|
||||||
// Add footer
|
// Add footer
|
||||||
$footer = $section->addFooter();
|
$footer = $section->addFooter();
|
||||||
$footer->addPreserveText(htmlspecialchars('Page {PAGE} of {NUMPAGES}.', ENT_COMPAT, 'UTF-8'), null, array('alignment' => \PhpOffice\PhpWord\SimpleType\Jc::CENTER));
|
$footer->addPreserveText('Page {PAGE} of {NUMPAGES}.', null, array('alignment' => \PhpOffice\PhpWord\SimpleType\Jc::CENTER));
|
||||||
$footer->addLink('https://github.com/PHPOffice/PHPWord', htmlspecialchars('PHPWord on GitHub', ENT_COMPAT, 'UTF-8'));
|
$footer->addLink('https://github.com/PHPOffice/PHPWord', 'PHPWord on GitHub');
|
||||||
|
|
||||||
// Write some text
|
// Write some text
|
||||||
$section->addTextBreak();
|
$section->addTextBreak();
|
||||||
$section->addText(htmlspecialchars('Some text...', ENT_COMPAT, 'UTF-8'));
|
$section->addText('Some text...');
|
||||||
|
|
||||||
// Create a second page
|
// Create a second page
|
||||||
$section->addPageBreak();
|
$section->addPageBreak();
|
||||||
|
|
||||||
// Write some text
|
// Write some text
|
||||||
$section->addTextBreak();
|
$section->addTextBreak();
|
||||||
$section->addText(htmlspecialchars('Some text...', ENT_COMPAT, 'UTF-8'));
|
$section->addText('Some text...');
|
||||||
|
|
||||||
// Create a third page
|
// Create a third page
|
||||||
$section->addPageBreak();
|
$section->addPageBreak();
|
||||||
|
|
||||||
// Write some text
|
// Write some text
|
||||||
$section->addTextBreak();
|
$section->addTextBreak();
|
||||||
$section->addText(htmlspecialchars('Some text...', ENT_COMPAT, 'UTF-8'));
|
$section->addText('Some text...');
|
||||||
|
|
||||||
// New portrait section
|
// New portrait section
|
||||||
$section2 = $phpWord->addSection();
|
$section2 = $phpWord->addSection();
|
||||||
|
|
||||||
$sec2Header = $section2->addHeader();
|
$sec2Header = $section2->addHeader();
|
||||||
$sec2Header->addText(htmlspecialchars('All pages in Section 2 will Have this!', ENT_COMPAT, 'UTF-8'));
|
$sec2Header->addText('All pages in Section 2 will Have this!');
|
||||||
|
|
||||||
// Write some text
|
// Write some text
|
||||||
$section2->addTextBreak();
|
$section2->addTextBreak();
|
||||||
$section2->addText(htmlspecialchars('Some text...', ENT_COMPAT, 'UTF-8'));
|
$section2->addText('Some text...');
|
||||||
|
|
||||||
// Save file
|
// Save file
|
||||||
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
||||||
|
|
|
||||||
|
|
@ -7,17 +7,17 @@ $phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||||
|
|
||||||
// Begin code
|
// Begin code
|
||||||
$section = $phpWord->addSection();
|
$section = $phpWord->addSection();
|
||||||
$section->addText(htmlspecialchars('Local image without any styles:', ENT_COMPAT, 'UTF-8'));
|
$section->addText('Local image without any styles:');
|
||||||
$section->addImage('resources/_mars.jpg');
|
$section->addImage('resources/_mars.jpg');
|
||||||
$section->addTextBreak(2);
|
$section->addTextBreak(2);
|
||||||
|
|
||||||
$section->addText(htmlspecialchars('Local image with styles:', ENT_COMPAT, 'UTF-8'));
|
$section->addText('Local image with styles:');
|
||||||
$section->addImage('resources/_earth.jpg', array('width' => 210, 'height' => 210, 'alignment' => \PhpOffice\PhpWord\SimpleType\Jc::CENTER));
|
$section->addImage('resources/_earth.jpg', array('width' => 210, 'height' => 210, 'alignment' => \PhpOffice\PhpWord\SimpleType\Jc::CENTER));
|
||||||
$section->addTextBreak(2);
|
$section->addTextBreak(2);
|
||||||
|
|
||||||
// Remote image
|
// Remote image
|
||||||
$source = 'http://php.net/images/logos/php-med-trans-light.gif';
|
$source = 'http://php.net/images/logos/php-med-trans-light.gif';
|
||||||
$section->addText(htmlspecialchars("Remote image from: {$source}", ENT_COMPAT, 'UTF-8'));
|
$section->addText("Remote image from: {$source}");
|
||||||
$section->addImage($source);
|
$section->addImage($source);
|
||||||
|
|
||||||
//Wrapping style
|
//Wrapping style
|
||||||
|
|
@ -25,7 +25,7 @@ $text = str_repeat('Hello World! ', 15);
|
||||||
$wrappingStyles = array('inline', 'behind', 'infront', 'square', 'tight');
|
$wrappingStyles = array('inline', 'behind', 'infront', 'square', 'tight');
|
||||||
foreach ($wrappingStyles as $wrappingStyle) {
|
foreach ($wrappingStyles as $wrappingStyle) {
|
||||||
$section->addTextBreak(5);
|
$section->addTextBreak(5);
|
||||||
$section->addText(htmlspecialchars("Wrapping style {$wrappingStyle}", ENT_COMPAT, 'UTF-8'));
|
$section->addText("Wrapping style {$wrappingStyle}");
|
||||||
$section->addImage(
|
$section->addImage(
|
||||||
'resources/_earth.jpg',
|
'resources/_earth.jpg',
|
||||||
array(
|
array(
|
||||||
|
|
@ -37,12 +37,12 @@ foreach ($wrappingStyles as $wrappingStyle) {
|
||||||
'wrappingStyle' => $wrappingStyle,
|
'wrappingStyle' => $wrappingStyle,
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
$section->addText(htmlspecialchars($text, ENT_COMPAT, 'UTF-8'));
|
$section->addText($text);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Absolute positioning
|
//Absolute positioning
|
||||||
$section->addTextBreak(3);
|
$section->addTextBreak(3);
|
||||||
$section->addText(htmlspecialchars('Absolute positioning: see top right corner of page', ENT_COMPAT, 'UTF-8'));
|
$section->addText('Absolute positioning: see top right corner of page');
|
||||||
$section->addImage(
|
$section->addImage(
|
||||||
'resources/_mars.jpg',
|
'resources/_mars.jpg',
|
||||||
array(
|
array(
|
||||||
|
|
@ -59,8 +59,8 @@ $section->addImage(
|
||||||
|
|
||||||
//Relative positioning
|
//Relative positioning
|
||||||
$section->addTextBreak(3);
|
$section->addTextBreak(3);
|
||||||
$section->addText(htmlspecialchars('Relative positioning: Horizontal position center relative to column,', ENT_COMPAT, 'UTF-8'));
|
$section->addText('Relative positioning: Horizontal position center relative to column,');
|
||||||
$section->addText(htmlspecialchars('Vertical position top relative to line', ENT_COMPAT, 'UTF-8'));
|
$section->addText('Vertical position top relative to line');
|
||||||
$section->addImage(
|
$section->addImage(
|
||||||
'resources/_mars.jpg',
|
'resources/_mars.jpg',
|
||||||
array(
|
array(
|
||||||
|
|
|
||||||
|
|
@ -5,15 +5,16 @@ include_once 'Sample_Header.php';
|
||||||
echo date('H:i:s'), ' Create new PhpWord object', EOL;
|
echo date('H:i:s'), ' Create new PhpWord object', EOL;
|
||||||
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||||
|
|
||||||
// Begin code
|
// Define styles
|
||||||
$section = $phpWord->addSection();
|
$fontStyleName = 'myOwnStyle';
|
||||||
|
$phpWord->addFontStyle($fontStyleName, array('color' => 'FF0000'));
|
||||||
|
|
||||||
// Style definition
|
$paragraphStyleName = 'P-Style';
|
||||||
|
$phpWord->addParagraphStyle($paragraphStyleName, array('spaceAfter' => 95));
|
||||||
|
|
||||||
$phpWord->addFontStyle('myOwnStyle', array('color' => 'FF0000'));
|
$multilevelNumberingStyleName = 'multilevel';
|
||||||
$phpWord->addParagraphStyle('P-Style', array('spaceAfter' => 95));
|
|
||||||
$phpWord->addNumberingStyle(
|
$phpWord->addNumberingStyle(
|
||||||
'multilevel',
|
$multilevelNumberingStyleName,
|
||||||
array(
|
array(
|
||||||
'type' => 'multilevel',
|
'type' => 'multilevel',
|
||||||
'levels' => array(
|
'levels' => array(
|
||||||
|
|
@ -22,56 +23,59 @@ $phpWord->addNumberingStyle(
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
$predefinedMultilevel = array('listType' => \PhpOffice\PhpWord\Style\ListItem::TYPE_NUMBER_NESTED);
|
|
||||||
|
$predefinedMultilevelStyle = array('listType' => \PhpOffice\PhpWord\Style\ListItem::TYPE_NUMBER_NESTED);
|
||||||
|
|
||||||
|
// New section
|
||||||
|
$section = $phpWord->addSection();
|
||||||
|
|
||||||
// Lists
|
// Lists
|
||||||
|
$section->addText('Multilevel list.');
|
||||||
$section->addText(htmlspecialchars('Multilevel list.', ENT_COMPAT, 'UTF-8'));
|
$section->addListItem('List Item I', 0, null, $multilevelNumberingStyleName);
|
||||||
$section->addListItem(htmlspecialchars('List Item I', ENT_COMPAT, 'UTF-8'), 0, null, 'multilevel');
|
$section->addListItem('List Item I.a', 1, null, $multilevelNumberingStyleName);
|
||||||
$section->addListItem(htmlspecialchars('List Item I.a', ENT_COMPAT, 'UTF-8'), 1, null, 'multilevel');
|
$section->addListItem('List Item I.b', 1, null, $multilevelNumberingStyleName);
|
||||||
$section->addListItem(htmlspecialchars('List Item I.b', ENT_COMPAT, 'UTF-8'), 1, null, 'multilevel');
|
$section->addListItem('List Item II', 0, null, $multilevelNumberingStyleName);
|
||||||
$section->addListItem(htmlspecialchars('List Item II', ENT_COMPAT, 'UTF-8'), 0, null, 'multilevel');
|
$section->addListItem('List Item II.a', 1, null, $multilevelNumberingStyleName);
|
||||||
$section->addListItem(htmlspecialchars('List Item II.a', ENT_COMPAT, 'UTF-8'), 1, null, 'multilevel');
|
$section->addListItem('List Item III', 0, null, $multilevelNumberingStyleName);
|
||||||
$section->addListItem(htmlspecialchars('List Item III', ENT_COMPAT, 'UTF-8'), 0, null, 'multilevel');
|
|
||||||
$section->addTextBreak(2);
|
$section->addTextBreak(2);
|
||||||
|
|
||||||
$section->addText(htmlspecialchars('Basic simple bulleted list.', ENT_COMPAT, 'UTF-8'));
|
$section->addText('Basic simple bulleted list.');
|
||||||
$section->addListItem(htmlspecialchars('List Item 1', ENT_COMPAT, 'UTF-8'));
|
$section->addListItem('List Item 1');
|
||||||
$section->addListItem(htmlspecialchars('List Item 2', ENT_COMPAT, 'UTF-8'));
|
$section->addListItem('List Item 2');
|
||||||
$section->addListItem(htmlspecialchars('List Item 3', ENT_COMPAT, 'UTF-8'));
|
$section->addListItem('List Item 3');
|
||||||
$section->addTextBreak(2);
|
$section->addTextBreak(2);
|
||||||
|
|
||||||
$section->addText(htmlspecialchars('Continue from multilevel list above.', ENT_COMPAT, 'UTF-8'));
|
$section->addText('Continue from multilevel list above.');
|
||||||
$section->addListItem(htmlspecialchars('List Item IV', ENT_COMPAT, 'UTF-8'), 0, null, 'multilevel');
|
$section->addListItem('List Item IV', 0, null, $multilevelNumberingStyleName);
|
||||||
$section->addListItem(htmlspecialchars('List Item IV.a', ENT_COMPAT, 'UTF-8'), 1, null, 'multilevel');
|
$section->addListItem('List Item IV.a', 1, null, $multilevelNumberingStyleName);
|
||||||
$section->addTextBreak(2);
|
$section->addTextBreak(2);
|
||||||
|
|
||||||
$section->addText(htmlspecialchars('Multilevel predefined list.', ENT_COMPAT, 'UTF-8'));
|
$section->addText('Multilevel predefined list.');
|
||||||
$section->addListItem(htmlspecialchars('List Item 1', ENT_COMPAT, 'UTF-8'), 0, 'myOwnStyle', $predefinedMultilevel, 'P-Style');
|
$section->addListItem('List Item 1', 0, $fontStyleName, $predefinedMultilevelStyle, $paragraphStyleName);
|
||||||
$section->addListItem(htmlspecialchars('List Item 2', ENT_COMPAT, 'UTF-8'), 0, 'myOwnStyle', $predefinedMultilevel, 'P-Style');
|
$section->addListItem('List Item 2', 0, $fontStyleName, $predefinedMultilevelStyle, $paragraphStyleName);
|
||||||
$section->addListItem(htmlspecialchars('List Item 3', ENT_COMPAT, 'UTF-8'), 1, 'myOwnStyle', $predefinedMultilevel, 'P-Style');
|
$section->addListItem('List Item 3', 1, $fontStyleName, $predefinedMultilevelStyle, $paragraphStyleName);
|
||||||
$section->addListItem(htmlspecialchars('List Item 4', ENT_COMPAT, 'UTF-8'), 1, 'myOwnStyle', $predefinedMultilevel, 'P-Style');
|
$section->addListItem('List Item 4', 1, $fontStyleName, $predefinedMultilevelStyle, $paragraphStyleName);
|
||||||
$section->addListItem(htmlspecialchars('List Item 5', ENT_COMPAT, 'UTF-8'), 2, 'myOwnStyle', $predefinedMultilevel, 'P-Style');
|
$section->addListItem('List Item 5', 2, $fontStyleName, $predefinedMultilevelStyle, $paragraphStyleName);
|
||||||
$section->addListItem(htmlspecialchars('List Item 6', ENT_COMPAT, 'UTF-8'), 1, 'myOwnStyle', $predefinedMultilevel, 'P-Style');
|
$section->addListItem('List Item 6', 1, $fontStyleName, $predefinedMultilevelStyle, $paragraphStyleName);
|
||||||
$section->addListItem(htmlspecialchars('List Item 7', ENT_COMPAT, 'UTF-8'), 0, 'myOwnStyle', $predefinedMultilevel, 'P-Style');
|
$section->addListItem('List Item 7', 0, $fontStyleName, $predefinedMultilevelStyle, $paragraphStyleName);
|
||||||
$section->addTextBreak(2);
|
$section->addTextBreak(2);
|
||||||
|
|
||||||
$section->addText(htmlspecialchars('List with inline formatting.', ENT_COMPAT, 'UTF-8'));
|
$section->addText('List with inline formatting.');
|
||||||
$listItemRun = $section->addListItemRun();
|
$listItemRun = $section->addListItemRun();
|
||||||
$listItemRun->addText(htmlspecialchars('List item 1', ENT_COMPAT, 'UTF-8'));
|
$listItemRun->addText('List item 1');
|
||||||
$listItemRun->addText(htmlspecialchars(' in bold', ENT_COMPAT, 'UTF-8'), array('bold' => true));
|
$listItemRun->addText(' in bold', array('bold' => true));
|
||||||
$listItemRun = $section->addListItemRun();
|
$listItemRun = $section->addListItemRun();
|
||||||
$listItemRun->addText(htmlspecialchars('List item 2', ENT_COMPAT, 'UTF-8'));
|
$listItemRun->addText('List item 2');
|
||||||
$listItemRun->addText(htmlspecialchars(' in italic', ENT_COMPAT, 'UTF-8'), array('italic' => true));
|
$listItemRun->addText(' in italic', array('italic' => true));
|
||||||
$listItemRun = $section->addListItemRun();
|
$listItemRun = $section->addListItemRun();
|
||||||
$listItemRun->addText(htmlspecialchars('List item 3', ENT_COMPAT, 'UTF-8'));
|
$listItemRun->addText('List item 3');
|
||||||
$listItemRun->addText(htmlspecialchars(' underlined', ENT_COMPAT, 'UTF-8'), array('underline' => 'dash'));
|
$listItemRun->addText(' underlined', array('underline' => 'dash'));
|
||||||
$section->addTextBreak(2);
|
$section->addTextBreak(2);
|
||||||
|
|
||||||
// Numbered heading
|
// Numbered heading
|
||||||
|
$headingNumberingStyleName = 'headingNumbering';
|
||||||
$phpWord->addNumberingStyle(
|
$phpWord->addNumberingStyle(
|
||||||
'headingNumbering',
|
$headingNumberingStyleName,
|
||||||
array('type' => 'multilevel',
|
array('type' => 'multilevel',
|
||||||
'levels' => array(
|
'levels' => array(
|
||||||
array('pStyle' => 'Heading1', 'format' => 'decimal', 'text' => '%1'),
|
array('pStyle' => 'Heading1', 'format' => 'decimal', 'text' => '%1'),
|
||||||
|
|
@ -80,13 +84,13 @@ $phpWord->addNumberingStyle(
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
$phpWord->addTitleStyle(1, array('size' => 16), array('numStyle' => 'headingNumbering', 'numLevel' => 0));
|
$phpWord->addTitleStyle(1, array('size' => 16), array('numStyle' => $headingNumberingStyleName, 'numLevel' => 0));
|
||||||
$phpWord->addTitleStyle(2, array('size' => 14), array('numStyle' => 'headingNumbering', 'numLevel' => 1));
|
$phpWord->addTitleStyle(2, array('size' => 14), array('numStyle' => $headingNumberingStyleName, 'numLevel' => 1));
|
||||||
$phpWord->addTitleStyle(3, array('size' => 12), array('numStyle' => 'headingNumbering', 'numLevel' => 2));
|
$phpWord->addTitleStyle(3, array('size' => 12), array('numStyle' => $headingNumberingStyleName, 'numLevel' => 2));
|
||||||
|
|
||||||
$section->addTitle(htmlspecialchars('Heading 1', ENT_COMPAT, 'UTF-8'), 1);
|
$section->addTitle('Heading 1', 1);
|
||||||
$section->addTitle(htmlspecialchars('Heading 2', ENT_COMPAT, 'UTF-8'), 2);
|
$section->addTitle('Heading 2', 2);
|
||||||
$section->addTitle(htmlspecialchars('Heading 3', ENT_COMPAT, 'UTF-8'), 3);
|
$section->addTitle('Heading 3', 3);
|
||||||
|
|
||||||
// Save file
|
// Save file
|
||||||
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
||||||
|
|
|
||||||
|
|
@ -5,20 +5,22 @@ include_once 'Sample_Header.php';
|
||||||
echo date('H:i:s'), ' Create new PhpWord object', EOL;
|
echo date('H:i:s'), ' Create new PhpWord object', EOL;
|
||||||
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||||
|
|
||||||
// Begin code
|
// Define styles
|
||||||
|
$linkFontStyleName = 'myOwnLinStyle';
|
||||||
|
$phpWord->addLinkStyle($linkFontStyleName, array('bold' => true, 'color' => '808000'));
|
||||||
|
|
||||||
|
// New section
|
||||||
$section = $phpWord->addSection();
|
$section = $phpWord->addSection();
|
||||||
|
|
||||||
// Add hyperlink elements
|
// Add hyperlink elements
|
||||||
$section->addLink(
|
$section->addLink(
|
||||||
'https://github.com/PHPOffice/PHPWord',
|
'https://github.com/PHPOffice/PHPWord',
|
||||||
htmlspecialchars('PHPWord on GitHub', ENT_COMPAT, 'UTF-8'),
|
'PHPWord on GitHub',
|
||||||
array('color' => '0000FF', 'underline' => \PhpOffice\PhpWord\Style\Font::UNDERLINE_SINGLE)
|
array('color' => '0000FF', 'underline' => \PhpOffice\PhpWord\Style\Font::UNDERLINE_SINGLE)
|
||||||
);
|
);
|
||||||
$section->addTextBreak(2);
|
$section->addTextBreak(2);
|
||||||
|
$section->addLink('http://www.bing.com', null, $linkFontStyleName);
|
||||||
$phpWord->addLinkStyle('myOwnLinkStyle', array('bold' => true, 'color' => '808000'));
|
$section->addLink('http://www.yahoo.com', null, $linkFontStyleName);
|
||||||
$section->addLink('http://www.bing.com', null, 'myOwnLinkStyle');
|
|
||||||
$section->addLink('http://www.yahoo.com', null, 'myOwnLinkStyle');
|
|
||||||
|
|
||||||
// Save file
|
// Save file
|
||||||
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ $phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||||
|
|
||||||
// Begin code
|
// Begin code
|
||||||
$section = $phpWord->addSection();
|
$section = $phpWord->addSection();
|
||||||
$section->addText(htmlspecialchars('You can open this OLE object by double clicking on the icon:', ENT_COMPAT, 'UTF-8'));
|
$section->addText('You can open this OLE object by double clicking on the icon:');
|
||||||
$section->addTextBreak(2);
|
$section->addTextBreak(2);
|
||||||
$section->addObject('resources/_sheet.xls');
|
$section->addObject('resources/_sheet.xls');
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,66 +5,63 @@ include_once 'Sample_Header.php';
|
||||||
echo date('H:i:s'), ' Create new PhpWord object', EOL;
|
echo date('H:i:s'), ' Create new PhpWord object', EOL;
|
||||||
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||||
|
|
||||||
// Begin code
|
// New section
|
||||||
$section = $phpWord->addSection();
|
$section = $phpWord->addSection();
|
||||||
|
|
||||||
// Define the TOC font style
|
// Define styles
|
||||||
$fontStyle = array('spaceAfter' => 60, 'size' => 12);
|
$fontStyle12 = array('spaceAfter' => 60, 'size' => 12);
|
||||||
$fontStyle2 = array('size' => 10);
|
$fontStyle10 = array('size' => 10);
|
||||||
|
|
||||||
// Add title styles
|
|
||||||
$phpWord->addTitleStyle(1, array('size' => 20, 'color' => '333333', 'bold' => true));
|
$phpWord->addTitleStyle(1, array('size' => 20, 'color' => '333333', 'bold' => true));
|
||||||
$phpWord->addTitleStyle(2, array('size' => 16, 'color' => '666666'));
|
$phpWord->addTitleStyle(2, array('size' => 16, 'color' => '666666'));
|
||||||
$phpWord->addTitleStyle(3, array('size' => 14, 'italic' => true));
|
$phpWord->addTitleStyle(3, array('size' => 14, 'italic' => true));
|
||||||
$phpWord->addTitleStyle(4, array('size' => 12));
|
$phpWord->addTitleStyle(4, array('size' => 12));
|
||||||
|
|
||||||
// Add text elements
|
// Add text elements
|
||||||
$section->addText(htmlspecialchars('Table of contents 1', ENT_COMPAT, 'UTF-8'));
|
$section->addText('Table of contents 1');
|
||||||
$section->addTextBreak(2);
|
$section->addTextBreak(2);
|
||||||
|
|
||||||
// Add TOC #1
|
// Add TOC #1
|
||||||
$toc = $section->addTOC($fontStyle);
|
$toc = $section->addTOC($fontStyle12);
|
||||||
$section->addTextBreak(2);
|
$section->addTextBreak(2);
|
||||||
|
|
||||||
// Filler
|
// Filler
|
||||||
$section->addText(htmlspecialchars('Text between TOC', ENT_COMPAT, 'UTF-8'));
|
$section->addText('Text between TOC');
|
||||||
$section->addTextBreak(2);
|
$section->addTextBreak(2);
|
||||||
|
|
||||||
// Add TOC #1
|
// Add TOC #1
|
||||||
$section->addText(htmlspecialchars('Table of contents 2', ENT_COMPAT, 'UTF-8'));
|
$section->addText('Table of contents 2');
|
||||||
$section->addTextBreak(2);
|
$section->addTextBreak(2);
|
||||||
$toc2 = $section->addTOC($fontStyle2);
|
$toc2 = $section->addTOC($fontStyle10);
|
||||||
$toc2->setMinDepth(2);
|
$toc2->setMinDepth(2);
|
||||||
$toc2->setMaxDepth(3);
|
$toc2->setMaxDepth(3);
|
||||||
|
|
||||||
|
|
||||||
// Add Titles
|
// Add Titles
|
||||||
$section->addPageBreak();
|
$section->addPageBreak();
|
||||||
$section->addTitle(htmlspecialchars('Foo & Bar', ENT_COMPAT, 'UTF-8'), 1);
|
$section->addTitle('Foo n Bar', 1);
|
||||||
$section->addText(htmlspecialchars('Some text...', ENT_COMPAT, 'UTF-8'));
|
$section->addText('Some text...');
|
||||||
$section->addTextBreak(2);
|
$section->addTextBreak(2);
|
||||||
|
|
||||||
$section->addTitle(htmlspecialchars('I am a Subtitle of Title 1', ENT_COMPAT, 'UTF-8'), 2);
|
$section->addTitle('I am a Subtitle of Title 1', 2);
|
||||||
$section->addTextBreak(2);
|
$section->addTextBreak(2);
|
||||||
$section->addText(htmlspecialchars('Some more text...', ENT_COMPAT, 'UTF-8'));
|
$section->addText('Some more text...');
|
||||||
$section->addTextBreak(2);
|
$section->addTextBreak(2);
|
||||||
|
|
||||||
$section->addTitle(htmlspecialchars('Another Title (Title 2)', ENT_COMPAT, 'UTF-8'), 1);
|
$section->addTitle('Another Title (Title 2)', 1);
|
||||||
$section->addText(htmlspecialchars('Some text...', ENT_COMPAT, 'UTF-8'));
|
$section->addText('Some text...');
|
||||||
$section->addPageBreak();
|
$section->addPageBreak();
|
||||||
$section->addTitle(htmlspecialchars('I am Title 3', ENT_COMPAT, 'UTF-8'), 1);
|
$section->addTitle('I am Title 3', 1);
|
||||||
$section->addText(htmlspecialchars('And more text...', ENT_COMPAT, 'UTF-8'));
|
$section->addText('And more text...');
|
||||||
$section->addTextBreak(2);
|
$section->addTextBreak(2);
|
||||||
$section->addTitle(htmlspecialchars('I am a Subtitle of Title 3', ENT_COMPAT, 'UTF-8'), 2);
|
$section->addTitle('I am a Subtitle of Title 3', 2);
|
||||||
$section->addText(htmlspecialchars('Again and again, more text...', ENT_COMPAT, 'UTF-8'));
|
$section->addText('Again and again, more text...');
|
||||||
$section->addTitle(htmlspecialchars('Subtitle 3.1.1', ENT_COMPAT, 'UTF-8'), 3);
|
$section->addTitle('Subtitle 3.1.1', 3);
|
||||||
$section->addText(htmlspecialchars('Text', ENT_COMPAT, 'UTF-8'));
|
$section->addText('Text');
|
||||||
$section->addTitle(htmlspecialchars('Subtitle 3.1.1.1', ENT_COMPAT, 'UTF-8'), 4);
|
$section->addTitle('Subtitle 3.1.1.1', 4);
|
||||||
$section->addText(htmlspecialchars('Text', ENT_COMPAT, 'UTF-8'));
|
$section->addText('Text');
|
||||||
$section->addTitle(htmlspecialchars('Subtitle 3.1.1.2', ENT_COMPAT, 'UTF-8'), 4);
|
$section->addTitle('Subtitle 3.1.1.2', 4);
|
||||||
$section->addText(htmlspecialchars('Text', ENT_COMPAT, 'UTF-8'));
|
$section->addText('Text');
|
||||||
$section->addTitle(htmlspecialchars('Subtitle 3.1.2', ENT_COMPAT, 'UTF-8'), 3);
|
$section->addTitle('Subtitle 3.1.2', 3);
|
||||||
$section->addText(htmlspecialchars('Text', ENT_COMPAT, 'UTF-8'));
|
$section->addText('Text');
|
||||||
|
|
||||||
echo date('H:i:s'), ' Note: Please refresh TOC manually.', EOL;
|
echo date('H:i:s'), ' Note: Please refresh TOC manually.', EOL;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,11 +6,10 @@ echo date('H:i:s'), ' Create new PhpWord object', EOL;
|
||||||
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||||
|
|
||||||
// Begin code
|
// Begin code
|
||||||
|
|
||||||
$section = $phpWord->addSection();
|
$section = $phpWord->addSection();
|
||||||
$header = $section->addHeader();
|
$header = $section->addHeader();
|
||||||
$header->addWatermark('resources/_earth.jpg', array('marginTop' => 200, 'marginLeft' => 55));
|
$header->addWatermark('resources/_earth.jpg', array('marginTop' => 200, 'marginLeft' => 55));
|
||||||
$section->addText(htmlspecialchars('The header reference to the current section includes a watermark image.', ENT_COMPAT, 'UTF-8'));
|
$section->addText('The header reference to the current section includes a watermark image.');
|
||||||
|
|
||||||
// Save file
|
// Save file
|
||||||
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
||||||
|
|
|
||||||
|
|
@ -5,25 +5,31 @@ include_once 'Sample_Header.php';
|
||||||
echo date('H:i:s'), ' Create new PhpWord object', EOL;
|
echo date('H:i:s'), ' Create new PhpWord object', EOL;
|
||||||
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||||
|
|
||||||
// Begin code
|
// Define styles
|
||||||
$fontStyle = array('size' => 24);
|
$fontStyle24 = array('size' => 24);
|
||||||
$paragraphStyle = array('spacing' => 240, 'size' => 24);
|
|
||||||
$phpWord->addFontStyle('fontStyle', array('size' => 9));
|
|
||||||
$phpWord->addParagraphStyle('paragraphStyle', array('spacing' => 480));
|
|
||||||
$fontStyle = array('size' => 24);
|
|
||||||
|
|
||||||
|
$paragraphStyle24 = array('spacing' => 240, 'size' => 24);
|
||||||
|
|
||||||
|
$fontStyleName = 'fontStyle';
|
||||||
|
$phpWord->addFontStyle($fontStyleName, array('size' => 9));
|
||||||
|
|
||||||
|
$paragraphStyleName = 'paragraphStyle';
|
||||||
|
$phpWord->addParagraphStyle($paragraphStyleName, array('spacing' => 480));
|
||||||
|
|
||||||
|
// New section
|
||||||
$section = $phpWord->addSection();
|
$section = $phpWord->addSection();
|
||||||
$section->addText(htmlspecialchars('Text break with no style:', ENT_COMPAT, 'UTF-8'));
|
|
||||||
|
$section->addText('Text break with no style:');
|
||||||
$section->addTextBreak();
|
$section->addTextBreak();
|
||||||
$section->addText(htmlspecialchars('Text break with defined font style:', ENT_COMPAT, 'UTF-8'));
|
$section->addText('Text break with defined font style:');
|
||||||
$section->addTextBreak(1, 'fontStyle');
|
$section->addTextBreak(1, $fontStyleName);
|
||||||
$section->addText(htmlspecialchars('Text break with defined paragraph style:', ENT_COMPAT, 'UTF-8'));
|
$section->addText('Text break with defined paragraph style:');
|
||||||
$section->addTextBreak(1, null, 'paragraphStyle');
|
$section->addTextBreak(1, null, $paragraphStyleName);
|
||||||
$section->addText(htmlspecialchars('Text break with inline font style:', ENT_COMPAT, 'UTF-8'));
|
$section->addText('Text break with inline font style:');
|
||||||
$section->addTextBreak(1, $fontStyle);
|
$section->addTextBreak(1, $fontStyle24);
|
||||||
$section->addText(htmlspecialchars('Text break with inline paragraph style:', ENT_COMPAT, 'UTF-8'));
|
$section->addText('Text break with inline paragraph style:');
|
||||||
$section->addTextBreak(1, null, $paragraphStyle);
|
$section->addTextBreak(1, null, $paragraphStyle24);
|
||||||
$section->addText(htmlspecialchars('Done.', ENT_COMPAT, 'UTF-8'));
|
$section->addText('Done.');
|
||||||
|
|
||||||
// Save file
|
// Save file
|
||||||
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
||||||
|
|
|
||||||
|
|
@ -4,17 +4,16 @@ include_once 'Sample_Header.php';
|
||||||
// New Word document
|
// New Word document
|
||||||
echo date('H:i:s'), ' Create new PhpWord object', EOL;
|
echo date('H:i:s'), ' Create new PhpWord object', EOL;
|
||||||
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||||
|
|
||||||
|
// New section
|
||||||
$section = $phpWord->addSection();
|
$section = $phpWord->addSection();
|
||||||
|
|
||||||
$section->addText(
|
$section->addText(
|
||||||
htmlspecialchars('This is some text highlighted using fgColor (limited to 15 colors) ', ENT_COMPAT, 'UTF-8'),
|
'This is some text highlighted using fgColor (limited to 15 colors)',
|
||||||
array('fgColor' => \PhpOffice\PhpWord\Style\Font::FGCOLOR_YELLOW)
|
array('fgColor' => \PhpOffice\PhpWord\Style\Font::FGCOLOR_YELLOW)
|
||||||
);
|
);
|
||||||
$section->addText(
|
$section->addText('This one uses bgColor and is using hex value (0xfbbb10)', array('bgColor' => 'fbbb10'));
|
||||||
htmlspecialchars('This one uses bgColor and is using hex value (0xfbbb10)', ENT_COMPAT, 'UTF-8'),
|
$section->addText('Compatible with font colors', array('color' => '0000ff', 'bgColor' => 'fbbb10'));
|
||||||
array('bgColor' => 'fbbb10')
|
|
||||||
);
|
|
||||||
$section->addText(htmlspecialchars('Compatible with font colors', ENT_COMPAT, 'UTF-8'), array('color' => '0000ff', 'bgColor' => 'fbbb10'));
|
|
||||||
|
|
||||||
// Save file
|
// Save file
|
||||||
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
||||||
|
|
|
||||||
|
|
@ -4,19 +4,15 @@ include_once 'Sample_Header.php';
|
||||||
// New Word document
|
// New Word document
|
||||||
echo date('H:i:s'), ' Create new PhpWord object', EOL;
|
echo date('H:i:s'), ' Create new PhpWord object', EOL;
|
||||||
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||||
|
|
||||||
|
// New section
|
||||||
$section = $phpWord->addSection();
|
$section = $phpWord->addSection();
|
||||||
|
|
||||||
$section->addText(htmlspecialchars('By default, when you insert an image, it adds a textbreak after its content.', ENT_COMPAT, 'UTF-8'));
|
$section->addText('By default, when you insert an image, it adds a textbreak after its content.');
|
||||||
|
$section->addText('If we want a simple border around an image, we wrap the image inside a table->row->cell');
|
||||||
$section->addText(
|
$section->addText(
|
||||||
htmlspecialchars('If we want a simple border around an image, we wrap the image inside a table->row->cell', ENT_COMPAT, 'UTF-8')
|
|
||||||
);
|
|
||||||
$section->addText(
|
|
||||||
htmlspecialchars(
|
|
||||||
'On the image with the red border, even if we set the row height to the height of the image, '
|
'On the image with the red border, even if we set the row height to the height of the image, '
|
||||||
. 'the textbreak is still there:',
|
. 'the textbreak is still there:'
|
||||||
ENT_COMPAT,
|
|
||||||
'UTF-8'
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
$table1 = $section->addTable(array('cellMargin' => 0, 'cellMarginRight' => 0, 'cellMarginBottom' => 0, 'cellMarginLeft' => 0));
|
$table1 = $section->addTable(array('cellMargin' => 0, 'cellMarginRight' => 0, 'cellMarginBottom' => 0, 'cellMarginLeft' => 0));
|
||||||
|
|
@ -25,13 +21,7 @@ $cell1 = $table1->addCell(null, array('valign' => 'top', 'borderSize' => 30, 'bo
|
||||||
$cell1->addImage('./resources/_earth.jpg', array('width' => 250, 'height' => 250, 'alignment' => \PhpOffice\PhpWord\SimpleType\Jc::CENTER));
|
$cell1->addImage('./resources/_earth.jpg', array('width' => 250, 'height' => 250, 'alignment' => \PhpOffice\PhpWord\SimpleType\Jc::CENTER));
|
||||||
|
|
||||||
$section->addTextBreak();
|
$section->addTextBreak();
|
||||||
$section->addText(
|
$section->addText("But if we set the rowStyle 'exactHeight' to true, the real row height is used, removing the textbreak:");
|
||||||
htmlspecialchars(
|
|
||||||
"But if we set the rowStyle 'exactHeight' to true, the real row height is used, removing the textbreak:",
|
|
||||||
ENT_COMPAT,
|
|
||||||
'UTF-8'
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
$table2 = $section->addTable(
|
$table2 = $section->addTable(
|
||||||
array(
|
array(
|
||||||
|
|
@ -46,10 +36,8 @@ $cell2 = $table2->addCell(null, array('valign' => 'top', 'borderSize' => 30, 'bo
|
||||||
$cell2->addImage('./resources/_earth.jpg', array('width' => 250, 'height' => 250, 'alignment' => \PhpOffice\PhpWord\SimpleType\Jc::CENTER));
|
$cell2->addImage('./resources/_earth.jpg', array('width' => 250, 'height' => 250, 'alignment' => \PhpOffice\PhpWord\SimpleType\Jc::CENTER));
|
||||||
|
|
||||||
$section->addTextBreak();
|
$section->addTextBreak();
|
||||||
$section->addText(
|
$section->addText('In this example, image is 250px height. Rows are calculated in twips, and 1px = 15twips.');
|
||||||
htmlspecialchars('In this example, image is 250px height. Rows are calculated in twips, and 1px = 15twips.', ENT_COMPAT, 'UTF-8')
|
$section->addText('So: $' . "table2->addRow(3750, array('exactHeight'=>true));");
|
||||||
);
|
|
||||||
$section->addText(htmlspecialchars('So: $' . "table2->addRow(3750, array('exactHeight'=>true));", ENT_COMPAT, 'UTF-8'));
|
|
||||||
|
|
||||||
// Save file
|
// Save file
|
||||||
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
||||||
|
|
|
||||||
|
|
@ -5,14 +5,16 @@ include_once 'Sample_Header.php';
|
||||||
echo date('H:i:s'), ' Create new PhpWord object', EOL;
|
echo date('H:i:s'), ' Create new PhpWord object', EOL;
|
||||||
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||||
|
|
||||||
|
// New section
|
||||||
$section = $phpWord->addSection();
|
$section = $phpWord->addSection();
|
||||||
$section->addText(htmlspecialchars('Check box in section', ENT_COMPAT, 'UTF-8'));
|
|
||||||
$section->addCheckBox('chkBox1', htmlspecialchars('Checkbox 1', ENT_COMPAT, 'UTF-8'));
|
$section->addText('Check box in section');
|
||||||
$section->addText(htmlspecialchars('Check box in table cell', ENT_COMPAT, 'UTF-8'));
|
$section->addCheckBox('chkBox1', 'Checkbox 1');
|
||||||
|
$section->addText('Check box in table cell');
|
||||||
$table = $section->addTable();
|
$table = $section->addTable();
|
||||||
$table->addRow();
|
$table->addRow();
|
||||||
$cell = $table->addCell();
|
$cell = $table->addCell();
|
||||||
$cell->addCheckBox('chkBox2', htmlspecialchars('Checkbox 2', ENT_COMPAT, 'UTF-8'));
|
$cell->addCheckBox('chkBox2', 'Checkbox 2');
|
||||||
|
|
||||||
// Save file
|
// Save file
|
||||||
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ include_once 'Sample_Header.php';
|
||||||
echo date('H:i:s'), ' Create new PhpWord object', EOL;
|
echo date('H:i:s'), ' Create new PhpWord object', EOL;
|
||||||
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||||
|
|
||||||
|
// New section
|
||||||
$section = $phpWord->addSection();
|
$section = $phpWord->addSection();
|
||||||
|
|
||||||
// In section
|
// In section
|
||||||
|
|
@ -17,28 +18,28 @@ $textbox = $section->addTextBox(
|
||||||
'borderColor' => '#FF0000',
|
'borderColor' => '#FF0000',
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
$textbox->addText(htmlspecialchars('Text box content in section.', ENT_COMPAT, 'UTF-8'));
|
$textbox->addText('Text box content in section.');
|
||||||
$textbox->addText(htmlspecialchars('Another line.', ENT_COMPAT, 'UTF-8'));
|
$textbox->addText('Another line.');
|
||||||
$cell = $textbox->addTable()->addRow()->addCell();
|
$cell = $textbox->addTable()->addRow()->addCell();
|
||||||
$cell->addText(htmlspecialchars('Table inside textbox', ENT_COMPAT, 'UTF-8'));
|
$cell->addText('Table inside textbox');
|
||||||
|
|
||||||
// Inside table
|
// Inside table
|
||||||
$section->addTextBreak(2);
|
$section->addTextBreak(2);
|
||||||
$cell = $section->addTable()->addRow()->addCell(300);
|
$cell = $section->addTable()->addRow()->addCell(300);
|
||||||
$textbox = $cell->addTextBox(array('borderSize' => 1, 'borderColor' => '#0000FF', 'innerMargin' => 100));
|
$textbox = $cell->addTextBox(array('borderSize' => 1, 'borderColor' => '#0000FF', 'innerMargin' => 100));
|
||||||
$textbox->addText(htmlspecialchars('Textbox inside table', ENT_COMPAT, 'UTF-8'));
|
$textbox->addText('Textbox inside table');
|
||||||
|
|
||||||
// Inside header with textrun
|
// Inside header with textrun
|
||||||
$header = $section->addHeader();
|
$header = $section->addHeader();
|
||||||
$textbox = $header->addTextBox(array('width' => 600, 'borderSize' => 1, 'borderColor' => '#00FF00'));
|
$textbox = $header->addTextBox(array('width' => 600, 'borderSize' => 1, 'borderColor' => '#00FF00'));
|
||||||
$textrun = $textbox->addTextRun();
|
$textrun = $textbox->addTextRun();
|
||||||
$textrun->addText(htmlspecialchars('TextBox in header. TextBox can contain a TextRun ', ENT_COMPAT, 'UTF-8'));
|
$textrun->addText('TextBox in header. TextBox can contain a TextRun ');
|
||||||
$textrun->addText(htmlspecialchars('with bold text', ENT_COMPAT, 'UTF-8'), array('bold' => true));
|
$textrun->addText('with bold text', array('bold' => true));
|
||||||
$textrun->addText(htmlspecialchars(', ', ENT_COMPAT, 'UTF-8'));
|
$textrun->addText(', ');
|
||||||
$textrun->addLink('https://github.com/PHPOffice/PHPWord', htmlspecialchars('PHPWord on GitHub', ENT_COMPAT, 'UTF-8'));
|
$textrun->addLink('https://github.com/PHPOffice/PHPWord', 'PHPWord on GitHub');
|
||||||
$textrun->addText(htmlspecialchars(', and image ', ENT_COMPAT, 'UTF-8'));
|
$textrun->addText(', and image ');
|
||||||
$textrun->addImage('resources/_earth.jpg', array('width' => 18, 'height' => 18));
|
$textrun->addImage('resources/_earth.jpg', array('width' => 18, 'height' => 18));
|
||||||
$textrun->addText(htmlspecialchars('.', ENT_COMPAT, 'UTF-8'));
|
$textrun->addText('.');
|
||||||
|
|
||||||
// Save file
|
// Save file
|
||||||
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
||||||
|
|
|
||||||
|
|
@ -5,24 +5,24 @@ include_once 'Sample_Header.php';
|
||||||
echo date('H:i:s'), ' Create new PhpWord object', EOL;
|
echo date('H:i:s'), ' Create new PhpWord object', EOL;
|
||||||
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||||
|
|
||||||
// Begin code
|
// New section
|
||||||
$section = $phpWord->addSection();
|
$section = $phpWord->addSection();
|
||||||
|
|
||||||
// Add Field elements
|
// Add Field elements
|
||||||
// See Element/Field.php for all options
|
// See Element/Field.php for all options
|
||||||
$section->addText(htmlspecialchars('Date field:', ENT_COMPAT, 'UTF-8'));
|
$section->addText('Date field:');
|
||||||
$section->addField('DATE', array('dateformat' => 'dddd d MMMM yyyy H:mm:ss'), array('PreserveFormat'));
|
$section->addField('DATE', array('dateformat' => 'dddd d MMMM yyyy H:mm:ss'), array('PreserveFormat'));
|
||||||
|
|
||||||
$section->addText(htmlspecialchars('Page field:', ENT_COMPAT, 'UTF-8'));
|
$section->addText('Page field:');
|
||||||
$section->addField('PAGE', array('format' => 'ArabicDash'));
|
$section->addField('PAGE', array('format' => 'ArabicDash'));
|
||||||
|
|
||||||
$section->addText(htmlspecialchars('Number of pages field:', ENT_COMPAT, 'UTF-8'));
|
$section->addText('Number of pages field:');
|
||||||
$section->addField('NUMPAGES', array('format' => 'Arabic', 'numformat' => '0,00'), array('PreserveFormat'));
|
$section->addField('NUMPAGES', array('format' => 'Arabic', 'numformat' => '0,00'), array('PreserveFormat'));
|
||||||
|
|
||||||
$textrun = $section->addTextRun(array('alignment' => \PhpOffice\PhpWord\SimpleType\Jc::CENTER));
|
$textrun = $section->addTextRun(array('alignment' => \PhpOffice\PhpWord\SimpleType\Jc::CENTER));
|
||||||
$textrun->addText(htmlspecialchars('This is the date of lunar calendar ', ENT_COMPAT, 'UTF-8'));
|
$textrun->addText('This is the date of lunar calendar ');
|
||||||
$textrun->addField('DATE', array('dateformat' => 'd-M-yyyy H:mm:ss'), array('PreserveFormat', 'LunarCalendar'));
|
$textrun->addField('DATE', array('dateformat' => 'd-M-yyyy H:mm:ss'), array('PreserveFormat', 'LunarCalendar'));
|
||||||
$textrun->addText(htmlspecialchars(' written in a textrun.', ENT_COMPAT, 'UTF-8'));
|
$textrun->addText(' written in a textrun.');
|
||||||
|
|
||||||
// Save file
|
// Save file
|
||||||
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
||||||
|
|
|
||||||
|
|
@ -5,12 +5,12 @@ include_once 'Sample_Header.php';
|
||||||
echo date('H:i:s'), ' Create new PhpWord object', EOL;
|
echo date('H:i:s'), ' Create new PhpWord object', EOL;
|
||||||
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||||
|
|
||||||
// Begin code
|
// New section
|
||||||
$section = $phpWord->addSection();
|
$section = $phpWord->addSection();
|
||||||
|
|
||||||
// Add Line elements
|
// Add Line elements
|
||||||
// See Element/Line.php for all options
|
// See Element/Line.php for all options
|
||||||
$section->addText(htmlspecialchars('Horizontal Line (Inline style):', ENT_COMPAT, 'UTF-8'));
|
$section->addText('Horizontal Line (Inline style):');
|
||||||
$section->addLine(
|
$section->addLine(
|
||||||
array(
|
array(
|
||||||
'width' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(4),
|
'width' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(4),
|
||||||
|
|
@ -18,7 +18,7 @@ $section->addLine(
|
||||||
'positioning' => 'absolute',
|
'positioning' => 'absolute',
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
$section->addText(htmlspecialchars('Vertical Line (Inline style):', ENT_COMPAT, 'UTF-8'));
|
$section->addText('Vertical Line (Inline style):');
|
||||||
$section->addLine(
|
$section->addLine(
|
||||||
array(
|
array(
|
||||||
'width' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(0),
|
'width' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(0),
|
||||||
|
|
@ -29,7 +29,7 @@ $section->addLine(
|
||||||
// Two text break
|
// Two text break
|
||||||
$section->addTextBreak(1);
|
$section->addTextBreak(1);
|
||||||
|
|
||||||
$section->addText(htmlspecialchars('Positioned Line (red):', ENT_COMPAT, 'UTF-8'));
|
$section->addText('Positioned Line (red):');
|
||||||
$section->addLine(
|
$section->addLine(
|
||||||
array(
|
array(
|
||||||
'width' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(4),
|
'width' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(4),
|
||||||
|
|
@ -44,7 +44,7 @@ $section->addLine(
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
$section->addText(htmlspecialchars('Horizontal Formatted Line', ENT_COMPAT, 'UTF-8'));
|
$section->addText('Horizontal Formatted Line');
|
||||||
$section->addLine(
|
$section->addLine(
|
||||||
array(
|
array(
|
||||||
'width' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(15),
|
'width' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(15),
|
||||||
|
|
|
||||||
|
|
@ -3,14 +3,16 @@ include_once 'Sample_Header.php';
|
||||||
|
|
||||||
// New Word document
|
// New Word document
|
||||||
echo date('H:i:s'), ' Create new PhpWord object', EOL;
|
echo date('H:i:s'), ' Create new PhpWord object', EOL;
|
||||||
|
|
||||||
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||||
$phpWord->addTitleStyle(1, array('size' => 14, 'bold' => true));
|
|
||||||
|
|
||||||
|
// New section
|
||||||
$section = $phpWord->addSection();
|
$section = $phpWord->addSection();
|
||||||
|
|
||||||
|
// Define styles
|
||||||
|
$phpWord->addTitleStyle(1, array('size' => 14, 'bold' => true));
|
||||||
|
|
||||||
// Arc
|
// Arc
|
||||||
$section->addTitle(htmlspecialchars('Arc', ENT_COMPAT, 'UTF-8'), 1);
|
$section->addTitle('Arc', 1);
|
||||||
$section->addShape(
|
$section->addShape(
|
||||||
'arc',
|
'arc',
|
||||||
array(
|
array(
|
||||||
|
|
@ -21,7 +23,7 @@ $section->addShape(
|
||||||
);
|
);
|
||||||
|
|
||||||
// Curve
|
// Curve
|
||||||
$section->addTitle(htmlspecialchars('Curve', ENT_COMPAT, 'UTF-8'), 1);
|
$section->addTitle('Curve', 1);
|
||||||
$section->addShape(
|
$section->addShape(
|
||||||
'curve',
|
'curve',
|
||||||
array(
|
array(
|
||||||
|
|
@ -38,7 +40,7 @@ $section->addShape(
|
||||||
);
|
);
|
||||||
|
|
||||||
// Line
|
// Line
|
||||||
$section->addTitle(htmlspecialchars('Line', ENT_COMPAT, 'UTF-8'), 1);
|
$section->addTitle('Line', 1);
|
||||||
$section->addShape(
|
$section->addShape(
|
||||||
'line',
|
'line',
|
||||||
array(
|
array(
|
||||||
|
|
@ -54,7 +56,7 @@ $section->addShape(
|
||||||
);
|
);
|
||||||
|
|
||||||
// Polyline
|
// Polyline
|
||||||
$section->addTitle(htmlspecialchars('Polyline', ENT_COMPAT, 'UTF-8'), 1);
|
$section->addTitle('Polyline', 1);
|
||||||
$section->addShape(
|
$section->addShape(
|
||||||
'polyline',
|
'polyline',
|
||||||
array(
|
array(
|
||||||
|
|
@ -64,7 +66,7 @@ $section->addShape(
|
||||||
);
|
);
|
||||||
|
|
||||||
// Rectangle
|
// Rectangle
|
||||||
$section->addTitle(htmlspecialchars('Rectangle', ENT_COMPAT, 'UTF-8'), 1);
|
$section->addTitle('Rectangle', 1);
|
||||||
$section->addShape(
|
$section->addShape(
|
||||||
'rect',
|
'rect',
|
||||||
array(
|
array(
|
||||||
|
|
@ -77,7 +79,7 @@ $section->addShape(
|
||||||
);
|
);
|
||||||
|
|
||||||
// Oval
|
// Oval
|
||||||
$section->addTitle(htmlspecialchars('Oval', ENT_COMPAT, 'UTF-8'), 1);
|
$section->addTitle('Oval', 1);
|
||||||
$section->addShape(
|
$section->addShape(
|
||||||
'oval',
|
'oval',
|
||||||
array(
|
array(
|
||||||
|
|
|
||||||
|
|
@ -5,14 +5,15 @@ use PhpOffice\PhpWord\Shared\Converter;
|
||||||
|
|
||||||
// New Word document
|
// New Word document
|
||||||
echo date('H:i:s'), ' Create new PhpWord object', EOL;
|
echo date('H:i:s'), ' Create new PhpWord object', EOL;
|
||||||
|
|
||||||
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||||
|
|
||||||
|
// Define styles
|
||||||
$phpWord->addTitleStyle(1, array('size' => 14, 'bold' => true), array('keepNext' => true, 'spaceBefore' => 240));
|
$phpWord->addTitleStyle(1, array('size' => 14, 'bold' => true), array('keepNext' => true, 'spaceBefore' => 240));
|
||||||
$phpWord->addTitleStyle(2, array('size' => 14, 'bold' => true), array('keepNext' => true, 'spaceBefore' => 240));
|
$phpWord->addTitleStyle(2, array('size' => 14, 'bold' => true), array('keepNext' => true, 'spaceBefore' => 240));
|
||||||
|
|
||||||
// 2D charts
|
// 2D charts
|
||||||
$section = $phpWord->addSection();
|
$section = $phpWord->addSection();
|
||||||
$section->addTitle(htmlspecialchars('2D charts', ENT_COMPAT, 'UTF-8'), 1);
|
$section->addTitle('2D charts', 1);
|
||||||
$section = $phpWord->addSection(array('colsNum' => 2, 'breakType' => 'continuous'));
|
$section = $phpWord->addSection(array('colsNum' => 2, 'breakType' => 'continuous'));
|
||||||
|
|
||||||
$chartTypes = array('pie', 'doughnut', 'bar', 'column', 'line', 'area', 'scatter', 'radar');
|
$chartTypes = array('pie', 'doughnut', 'bar', 'column', 'line', 'area', 'scatter', 'radar');
|
||||||
|
|
@ -38,7 +39,7 @@ foreach ($chartTypes as $chartType) {
|
||||||
|
|
||||||
// 3D charts
|
// 3D charts
|
||||||
$section = $phpWord->addSection(array('breakType' => 'continuous'));
|
$section = $phpWord->addSection(array('breakType' => 'continuous'));
|
||||||
$section->addTitle(htmlspecialchars('3D charts', ENT_COMPAT, 'UTF-8'), 1);
|
$section->addTitle('3D charts', 1);
|
||||||
$section = $phpWord->addSection(array('colsNum' => 2, 'breakType' => 'continuous'));
|
$section = $phpWord->addSection(array('colsNum' => 2, 'breakType' => 'continuous'));
|
||||||
|
|
||||||
$chartTypes = array('pie', 'bar', 'column', 'line', 'area');
|
$chartTypes = array('pie', 'bar', 'column', 'line', 'area');
|
||||||
|
|
|
||||||
|
|
@ -6,18 +6,19 @@ echo date('H:i:s'), ' Create new PhpWord object', EOL;
|
||||||
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||||
$phpWord->getProtection()->setEditing('forms');
|
$phpWord->getProtection()->setEditing('forms');
|
||||||
|
|
||||||
|
// New section
|
||||||
$section = $phpWord->addSection();
|
$section = $phpWord->addSection();
|
||||||
|
|
||||||
$textrun = $section->addTextRun();
|
$textrun = $section->addTextRun();
|
||||||
$textrun->addText(htmlspecialchars('Form fields can be added in a text run and can be in form of textinput ', ENT_COMPAT, 'UTF-8'));
|
$textrun->addText('Form fields can be added in a text run and can be in form of textinput ');
|
||||||
$textrun->addFormField('textinput')->setName('MyTextBox');
|
$textrun->addFormField('textinput')->setName('MyTextBox');
|
||||||
$textrun->addText(htmlspecialchars(', checkbox ', ENT_COMPAT, 'UTF-8'));
|
$textrun->addText(', checkbox ');
|
||||||
$textrun->addFormField('checkbox')->setDefault(true);
|
$textrun->addFormField('checkbox')->setDefault(true);
|
||||||
$textrun->addText(htmlspecialchars(', or dropdown ', ENT_COMPAT, 'UTF-8'));
|
$textrun->addText(', or dropdown ');
|
||||||
$textrun->addFormField('dropdown')->setEntries(array('Choice 1', 'Choice 2', 'Choice 3'));
|
$textrun->addFormField('dropdown')->setEntries(array('Choice 1', 'Choice 2', 'Choice 3'));
|
||||||
$textrun->addText(htmlspecialchars('. You have to set document protection to "forms" to enable dropdown.', ENT_COMPAT, 'UTF-8'));
|
$textrun->addText('. You have to set document protection to "forms" to enable dropdown.');
|
||||||
|
|
||||||
$section->addText(htmlspecialchars('They can also be added as a stand alone paragraph.', ENT_COMPAT, 'UTF-8'));
|
$section->addText('They can also be added as a stand alone paragraph.');
|
||||||
$section->addFormField('textinput')->setValue('Your name');
|
$section->addFormField('textinput')->setValue('Your name');
|
||||||
|
|
||||||
// Save file
|
// Save file
|
||||||
|
|
|
||||||
|
|
@ -5,18 +5,19 @@ include_once 'Sample_Header.php';
|
||||||
echo date('H:i:s'), ' Create new PhpWord object', EOL;
|
echo date('H:i:s'), ' Create new PhpWord object', EOL;
|
||||||
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||||
|
|
||||||
|
// New section
|
||||||
$section = $phpWord->addSection();
|
$section = $phpWord->addSection();
|
||||||
|
|
||||||
$textrun = $section->addTextRun();
|
$textrun = $section->addTextRun();
|
||||||
$textrun->addText(htmlspecialchars('Combobox: ', ENT_COMPAT, 'UTF-8'));
|
$textrun->addText('Combobox: ');
|
||||||
$textrun->addSDT('comboBox')->setListItems(array('1' => 'Choice 1', '2' => 'Choice 2'));
|
$textrun->addSDT('comboBox')->setListItems(array('1' => 'Choice 1', '2' => 'Choice 2'));
|
||||||
|
|
||||||
$textrun = $section->addTextRun();
|
$textrun = $section->addTextRun();
|
||||||
$textrun->addText(htmlspecialchars('Date: ', ENT_COMPAT, 'UTF-8'));
|
$textrun->addText('Date: ');
|
||||||
$textrun->addSDT('date');
|
$textrun->addSDT('date');
|
||||||
|
|
||||||
$textrun = $section->addTextRun();
|
$textrun = $section->addTextRun();
|
||||||
$textrun->addText(htmlspecialchars('Drop down list: ', ENT_COMPAT, 'UTF-8'));
|
$textrun->addText('Drop down list: ');
|
||||||
$textrun->addSDT('dropDownList')->setListItems(array('1' => 'Choice 1', '2' => 'Choice 2'));
|
$textrun->addSDT('dropDownList')->setListItems(array('1' => 'Choice 1', '2' => 'Choice 2'));
|
||||||
|
|
||||||
// Save file
|
// Save file
|
||||||
|
|
|
||||||
|
|
@ -6,13 +6,13 @@ echo date('H:i:s'), ' Create new PhpWord object', EOL;
|
||||||
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||||
|
|
||||||
$section = $phpWord->addSection();
|
$section = $phpWord->addSection();
|
||||||
$section->addTitle(htmlspecialchars('This is page 1', ENT_COMPAT, 'UTF-8'), 1);
|
$section->addTitle('This is page 1', 1);
|
||||||
$linkIsInternal = true;
|
$linkIsInternal = true;
|
||||||
$section->addLink('MyBookmark', htmlspecialchars('Take me to page 3', ENT_COMPAT, 'UTF-8'), null, null, $linkIsInternal);
|
$section->addLink('MyBookmark', 'Take me to page 3', null, null, $linkIsInternal);
|
||||||
$section->addPageBreak();
|
$section->addPageBreak();
|
||||||
$section->addTitle(htmlspecialchars('This is page 2', ENT_COMPAT, 'UTF-8'), 1);
|
$section->addTitle('This is page 2', 1);
|
||||||
$section->addPageBreak();
|
$section->addPageBreak();
|
||||||
$section->addTitle(htmlspecialchars('This is page 3', ENT_COMPAT, 'UTF-8'), 1);
|
$section->addTitle('This is page 3', 1);
|
||||||
$section->addBookmark('MyBookmark');
|
$section->addBookmark('MyBookmark');
|
||||||
|
|
||||||
// Save file
|
// Save file
|
||||||
|
|
|
||||||
|
|
@ -5,12 +5,14 @@ include_once 'Sample_Header.php';
|
||||||
echo date('H:i:s'), ' Create new PhpWord object', EOL;
|
echo date('H:i:s'), ' Create new PhpWord object', EOL;
|
||||||
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||||
|
|
||||||
|
// New section
|
||||||
$section = $phpWord->addSection();
|
$section = $phpWord->addSection();
|
||||||
|
|
||||||
$textrun = $section->addTextRun();
|
$textrun = $section->addTextRun();
|
||||||
$textrun->addText(htmlspecialchars('This is a Left to Right paragraph.', ENT_COMPAT, 'UTF-8'));
|
$textrun->addText('This is a Left to Right paragraph.');
|
||||||
|
|
||||||
$textrun = $section->addTextRun(array('alignment' => \PhpOffice\PhpWord\SimpleType\Jc::END));
|
$textrun = $section->addTextRun(array('alignment' => \PhpOffice\PhpWord\SimpleType\Jc::END));
|
||||||
$textrun->addText(htmlspecialchars('سلام این یک پاراگراف راست به چپ است', ENT_COMPAT, 'UTF-8'), array('rtl' => true));
|
$textrun->addText('سلام این یک پاراگراف راست به چپ است', array('rtl' => true));
|
||||||
|
|
||||||
// Save file
|
// Save file
|
||||||
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,9 @@ if (null === Settings::getPdfRendererPath()) {
|
||||||
$writers['PDF'] = null;
|
$writers['PDF'] = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Turn output escaping on
|
||||||
|
Settings::setOutputEscapingEnabled(true);
|
||||||
|
|
||||||
// Return to the caller script when runs by CLI
|
// Return to the caller script when runs by CLI
|
||||||
if (CLI) {
|
if (CLI) {
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,46 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* This file is part of PHPWord - A pure PHP library for reading and writing
|
||||||
|
* word processing documents.
|
||||||
|
*
|
||||||
|
* PHPWord is free software distributed under the terms of the GNU Lesser
|
||||||
|
* General Public License version 3 as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please read the LICENSE
|
||||||
|
* file that was distributed with this source code. For the full list of
|
||||||
|
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
|
||||||
|
*
|
||||||
|
* @link https://github.com/PHPOffice/PHPWord
|
||||||
|
* @copyright 2010-2016 PHPWord contributors
|
||||||
|
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace PhpOffice\PhpWord\Escaper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @since 0.13.0
|
||||||
|
*
|
||||||
|
* @codeCoverageIgnore
|
||||||
|
*/
|
||||||
|
abstract class AbstractEscaper implements EscaperInterface
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @param string $subject
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
abstract protected function escapeSingleValue($subject);
|
||||||
|
|
||||||
|
public function escape($subject)
|
||||||
|
{
|
||||||
|
if (is_array($subject)) {
|
||||||
|
foreach ($subject as &$item) {
|
||||||
|
$item = $this->escapeSingleValue($item);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$subject = $this->escapeSingleValue($subject);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $subject;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -19,6 +19,8 @@ namespace PhpOffice\PhpWord\Escaper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @since 0.13.0
|
* @since 0.13.0
|
||||||
|
*
|
||||||
|
* @codeCoverageIgnore
|
||||||
*/
|
*/
|
||||||
interface EscaperInterface
|
interface EscaperInterface
|
||||||
{
|
{
|
||||||
|
|
@ -27,5 +29,5 @@ interface EscaperInterface
|
||||||
*
|
*
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public static function escape($subject);
|
public function escape($subject);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,31 +19,15 @@ namespace PhpOffice\PhpWord\Escaper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @since 0.13.0
|
* @since 0.13.0
|
||||||
|
*
|
||||||
|
* @codeCoverageIgnore
|
||||||
*/
|
*/
|
||||||
class RegExp implements EscaperInterface
|
class RegExp extends AbstractEscaper
|
||||||
{
|
{
|
||||||
const REG_EXP_DELIMITER = '/';
|
const REG_EXP_DELIMITER = '/';
|
||||||
|
|
||||||
/**
|
protected function escapeSingleValue($subject)
|
||||||
* @param string $subject
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
protected static function escapeSingleItem($subject)
|
|
||||||
{
|
{
|
||||||
return self::REG_EXP_DELIMITER . preg_quote($subject, self::REG_EXP_DELIMITER) . self::REG_EXP_DELIMITER . 'u';
|
return self::REG_EXP_DELIMITER . preg_quote($subject, self::REG_EXP_DELIMITER) . self::REG_EXP_DELIMITER . 'u';
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function escape($subject)
|
|
||||||
{
|
|
||||||
if (is_array($subject)) {
|
|
||||||
foreach ($subject as &$item) {
|
|
||||||
$item = self::escapeSingleItem($item);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$subject = self::escapeSingleItem($subject);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $subject;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,32 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* This file is part of PHPWord - A pure PHP library for reading and writing
|
||||||
|
* word processing documents.
|
||||||
|
*
|
||||||
|
* PHPWord is free software distributed under the terms of the GNU Lesser
|
||||||
|
* General Public License version 3 as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please read the LICENSE
|
||||||
|
* file that was distributed with this source code. For the full list of
|
||||||
|
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
|
||||||
|
*
|
||||||
|
* @link https://github.com/PHPOffice/PHPWord
|
||||||
|
* @copyright 2010-2016 PHPWord contributors
|
||||||
|
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace PhpOffice\PhpWord\Escaper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @since 0.13.0
|
||||||
|
*
|
||||||
|
* @codeCoverageIgnore
|
||||||
|
*/
|
||||||
|
class Xml extends AbstractEscaper
|
||||||
|
{
|
||||||
|
protected function escapeSingleValue($subject)
|
||||||
|
{
|
||||||
|
// todo: omit encoding parameter after migration onto PHP 5.4
|
||||||
|
return htmlspecialchars($subject, ENT_QUOTES, 'UTF-8');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -126,6 +126,14 @@ class Settings
|
||||||
*/
|
*/
|
||||||
private static $tempDir = '';
|
private static $tempDir = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enables built-in output escaping mechanism.
|
||||||
|
* Default value is `false` for backward compatibility with versions below 0.13.0.
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
private static $outputEscapingEnabled = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the compatibility option used by the XMLWriter
|
* Return the compatibility option used by the XMLWriter
|
||||||
*
|
*
|
||||||
|
|
@ -282,6 +290,7 @@ class Settings
|
||||||
* @since 0.12.0
|
* @since 0.12.0
|
||||||
*
|
*
|
||||||
* @param string $tempDir The user defined path to temporary directory.
|
* @param string $tempDir The user defined path to temporary directory.
|
||||||
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public static function setTempDir($tempDir)
|
public static function setTempDir($tempDir)
|
||||||
|
|
@ -307,6 +316,30 @@ class Settings
|
||||||
return $tempDir;
|
return $tempDir;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @since 0.13.0
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*
|
||||||
|
* @codeCoverageIgnore
|
||||||
|
*/
|
||||||
|
public static function isOutputEscapingEnabled()
|
||||||
|
{
|
||||||
|
return self::$outputEscapingEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @since 0.13.0
|
||||||
|
*
|
||||||
|
* @param boolean $outputEscapingEnabled
|
||||||
|
*
|
||||||
|
* @codeCoverageIgnore
|
||||||
|
*/
|
||||||
|
public static function setOutputEscapingEnabled($outputEscapingEnabled)
|
||||||
|
{
|
||||||
|
self::$outputEscapingEnabled = $outputEscapingEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get default font name
|
* Get default font name
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@
|
||||||
namespace PhpOffice\PhpWord;
|
namespace PhpOffice\PhpWord;
|
||||||
|
|
||||||
use PhpOffice\PhpWord\Escaper\RegExp;
|
use PhpOffice\PhpWord\Escaper\RegExp;
|
||||||
|
use PhpOffice\PhpWord\Escaper\Xml;
|
||||||
use PhpOffice\PhpWord\Exception\CopyFileException;
|
use PhpOffice\PhpWord\Exception\CopyFileException;
|
||||||
use PhpOffice\PhpWord\Exception\CreateTemporaryFileException;
|
use PhpOffice\PhpWord\Exception\CreateTemporaryFileException;
|
||||||
use PhpOffice\PhpWord\Exception\Exception;
|
use PhpOffice\PhpWord\Exception\Exception;
|
||||||
|
|
@ -105,6 +106,9 @@ class TemplateProcessor
|
||||||
/**
|
/**
|
||||||
* Applies XSL style sheet to template's parts.
|
* Applies XSL style sheet to template's parts.
|
||||||
*
|
*
|
||||||
|
* Note: since the method doesn't make any guess on logic of the provided XSL style sheet,
|
||||||
|
* make sure that output is correctly escaped. Otherwise you may get broken document.
|
||||||
|
*
|
||||||
* @param \DOMDocument $xslDOMDocument
|
* @param \DOMDocument $xslDOMDocument
|
||||||
* @param array $xslOptions
|
* @param array $xslOptions
|
||||||
* @param string $xslOptionsURI
|
* @param string $xslOptionsURI
|
||||||
|
|
@ -189,6 +193,11 @@ class TemplateProcessor
|
||||||
$replace = self::ensureUtf8Encoded($replace);
|
$replace = self::ensureUtf8Encoded($replace);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Settings::isOutputEscapingEnabled()) {
|
||||||
|
$xmlEscaper = new Xml();
|
||||||
|
$replace = $xmlEscaper->escape($replace);
|
||||||
|
}
|
||||||
|
|
||||||
$this->tempDocumentHeaders = $this->setValueForPart($search, $replace, $this->tempDocumentHeaders, $limit);
|
$this->tempDocumentHeaders = $this->setValueForPart($search, $replace, $this->tempDocumentHeaders, $limit);
|
||||||
$this->tempDocumentMainPart = $this->setValueForPart($search, $replace, $this->tempDocumentMainPart, $limit);
|
$this->tempDocumentMainPart = $this->setValueForPart($search, $replace, $this->tempDocumentMainPart, $limit);
|
||||||
$this->tempDocumentFooters = $this->setValueForPart($search, $replace, $this->tempDocumentFooters, $limit);
|
$this->tempDocumentFooters = $this->setValueForPart($search, $replace, $this->tempDocumentFooters, $limit);
|
||||||
|
|
@ -442,7 +451,8 @@ class TemplateProcessor
|
||||||
if (self::MAXIMUM_REPLACEMENTS_DEFAULT === $limit) {
|
if (self::MAXIMUM_REPLACEMENTS_DEFAULT === $limit) {
|
||||||
return str_replace($search, $replace, $documentPartXML);
|
return str_replace($search, $replace, $documentPartXML);
|
||||||
} else {
|
} else {
|
||||||
return preg_replace(RegExp::escape($search), $replace, $documentPartXML, $limit);
|
$regExpEscaper = new RegExp();
|
||||||
|
return preg_replace($regExpEscaper->escape($search), $replace, $documentPartXML, $limit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace PhpOffice\PhpWord\Writer\Word2007\Element;
|
namespace PhpOffice\PhpWord\Writer\Word2007\Element;
|
||||||
|
use PhpOffice\PhpWord\Settings;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* CheckBox element writer
|
* CheckBox element writer
|
||||||
|
|
@ -63,7 +64,7 @@ class CheckBox extends Text
|
||||||
$xmlWriter->startElement('w:r');
|
$xmlWriter->startElement('w:r');
|
||||||
$xmlWriter->startElement('w:instrText');
|
$xmlWriter->startElement('w:instrText');
|
||||||
$xmlWriter->writeAttribute('xml:space', 'preserve');
|
$xmlWriter->writeAttribute('xml:space', 'preserve');
|
||||||
$xmlWriter->writeRaw(' FORMCHECKBOX ');
|
$xmlWriter->text(' FORMCHECKBOX ');
|
||||||
$xmlWriter->endElement();// w:instrText
|
$xmlWriter->endElement();// w:instrText
|
||||||
$xmlWriter->endElement(); // w:r
|
$xmlWriter->endElement(); // w:r
|
||||||
$xmlWriter->startElement('w:r');
|
$xmlWriter->startElement('w:r');
|
||||||
|
|
@ -83,7 +84,11 @@ class CheckBox extends Text
|
||||||
|
|
||||||
$xmlWriter->startElement('w:t');
|
$xmlWriter->startElement('w:t');
|
||||||
$xmlWriter->writeAttribute('xml:space', 'preserve');
|
$xmlWriter->writeAttribute('xml:space', 'preserve');
|
||||||
|
if (Settings::isOutputEscapingEnabled()) {
|
||||||
|
$xmlWriter->text($this->getText($element->getText()));
|
||||||
|
} else {
|
||||||
$xmlWriter->writeRaw($this->getText($element->getText()));
|
$xmlWriter->writeRaw($this->getText($element->getText()));
|
||||||
|
}
|
||||||
$xmlWriter->endElement(); // w:t
|
$xmlWriter->endElement(); // w:t
|
||||||
$xmlWriter->endElement(); // w:r
|
$xmlWriter->endElement(); // w:r
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -79,9 +79,7 @@ class Field extends Text
|
||||||
$xmlWriter->endElement(); // w:noProof
|
$xmlWriter->endElement(); // w:noProof
|
||||||
$xmlWriter->endElement(); // w:rPr
|
$xmlWriter->endElement(); // w:rPr
|
||||||
|
|
||||||
$xmlWriter->startElement('w:t');
|
$xmlWriter->writeElement('w:t', '1');
|
||||||
$xmlWriter->writeRaw('1');
|
|
||||||
$xmlWriter->endElement(); // w:t
|
|
||||||
$xmlWriter->endElement(); // w:r
|
$xmlWriter->endElement(); // w:r
|
||||||
$xmlWriter->endElement(); // w:fldSimple
|
$xmlWriter->endElement(); // w:fldSimple
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@ namespace PhpOffice\PhpWord\Writer\Word2007\Element;
|
||||||
|
|
||||||
use PhpOffice\Common\XMLWriter;
|
use PhpOffice\Common\XMLWriter;
|
||||||
use PhpOffice\PhpWord\Element\FormField as FormFieldElement;
|
use PhpOffice\PhpWord\Element\FormField as FormFieldElement;
|
||||||
|
use PhpOffice\PhpWord\Settings;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* FormField element writer
|
* FormField element writer
|
||||||
|
|
@ -78,7 +79,7 @@ class FormField extends Text
|
||||||
$this->writeFontStyle();
|
$this->writeFontStyle();
|
||||||
$xmlWriter->startElement('w:instrText');
|
$xmlWriter->startElement('w:instrText');
|
||||||
$xmlWriter->writeAttribute('xml:space', 'preserve');
|
$xmlWriter->writeAttribute('xml:space', 'preserve');
|
||||||
$xmlWriter->writeRaw("{$instruction}");
|
$xmlWriter->text("{$instruction}");
|
||||||
$xmlWriter->endElement();// w:instrText
|
$xmlWriter->endElement();// w:instrText
|
||||||
$xmlWriter->endElement(); // w:r
|
$xmlWriter->endElement(); // w:r
|
||||||
|
|
||||||
|
|
@ -91,7 +92,11 @@ class FormField extends Text
|
||||||
$this->writeFontStyle();
|
$this->writeFontStyle();
|
||||||
$xmlWriter->startElement('w:t');
|
$xmlWriter->startElement('w:t');
|
||||||
$xmlWriter->writeAttribute('xml:space', 'preserve');
|
$xmlWriter->writeAttribute('xml:space', 'preserve');
|
||||||
|
if (Settings::isOutputEscapingEnabled()) {
|
||||||
|
$xmlWriter->text($value);
|
||||||
|
} else {
|
||||||
$xmlWriter->writeRaw($value);
|
$xmlWriter->writeRaw($value);
|
||||||
|
}
|
||||||
$xmlWriter->endElement(); // w:t
|
$xmlWriter->endElement(); // w:t
|
||||||
$xmlWriter->endElement(); // w:r
|
$xmlWriter->endElement(); // w:r
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace PhpOffice\PhpWord\Writer\Word2007\Element;
|
namespace PhpOffice\PhpWord\Writer\Word2007\Element;
|
||||||
|
use PhpOffice\PhpWord\Settings;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Link element writer
|
* Link element writer
|
||||||
|
|
@ -54,7 +55,11 @@ class Link extends Text
|
||||||
|
|
||||||
$xmlWriter->startElement('w:t');
|
$xmlWriter->startElement('w:t');
|
||||||
$xmlWriter->writeAttribute('xml:space', 'preserve');
|
$xmlWriter->writeAttribute('xml:space', 'preserve');
|
||||||
|
if (Settings::isOutputEscapingEnabled()) {
|
||||||
|
$xmlWriter->text($element->getText());
|
||||||
|
} else {
|
||||||
$xmlWriter->writeRaw($element->getText());
|
$xmlWriter->writeRaw($element->getText());
|
||||||
|
}
|
||||||
$xmlWriter->endElement(); // w:t
|
$xmlWriter->endElement(); // w:t
|
||||||
$xmlWriter->endElement(); // w:r
|
$xmlWriter->endElement(); // w:r
|
||||||
$xmlWriter->endElement(); // w:hyperlink
|
$xmlWriter->endElement(); // w:hyperlink
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace PhpOffice\PhpWord\Writer\Word2007\Element;
|
namespace PhpOffice\PhpWord\Writer\Word2007\Element;
|
||||||
|
use PhpOffice\PhpWord\Settings;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PreserveText element writer
|
* PreserveText element writer
|
||||||
|
|
@ -60,7 +61,11 @@ class PreserveText extends Text
|
||||||
|
|
||||||
$xmlWriter->startElement('w:instrText');
|
$xmlWriter->startElement('w:instrText');
|
||||||
$xmlWriter->writeAttribute('xml:space', 'preserve');
|
$xmlWriter->writeAttribute('xml:space', 'preserve');
|
||||||
|
if (Settings::isOutputEscapingEnabled()) {
|
||||||
|
$xmlWriter->text($text);
|
||||||
|
} else {
|
||||||
$xmlWriter->writeRaw($text);
|
$xmlWriter->writeRaw($text);
|
||||||
|
}
|
||||||
$xmlWriter->endElement();
|
$xmlWriter->endElement();
|
||||||
$xmlWriter->endElement();
|
$xmlWriter->endElement();
|
||||||
|
|
||||||
|
|
@ -82,7 +87,11 @@ class PreserveText extends Text
|
||||||
|
|
||||||
$xmlWriter->startElement('w:t');
|
$xmlWriter->startElement('w:t');
|
||||||
$xmlWriter->writeAttribute('xml:space', 'preserve');
|
$xmlWriter->writeAttribute('xml:space', 'preserve');
|
||||||
|
if (Settings::isOutputEscapingEnabled()) {
|
||||||
|
$xmlWriter->text($this->getText($text));
|
||||||
|
} else {
|
||||||
$xmlWriter->writeRaw($this->getText($text));
|
$xmlWriter->writeRaw($this->getText($text));
|
||||||
|
}
|
||||||
$xmlWriter->endElement();
|
$xmlWriter->endElement();
|
||||||
$xmlWriter->endElement();
|
$xmlWriter->endElement();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -58,9 +58,7 @@ class SDT extends Text
|
||||||
// Content
|
// Content
|
||||||
$xmlWriter->startElement('w:sdtContent');
|
$xmlWriter->startElement('w:sdtContent');
|
||||||
$xmlWriter->startElement('w:r');
|
$xmlWriter->startElement('w:r');
|
||||||
$xmlWriter->startElement('w:t');
|
$xmlWriter->writeElement('w:t', 'Pick value');
|
||||||
$xmlWriter->writeRaw('Pick value');
|
|
||||||
$xmlWriter->endElement(); // w:t
|
|
||||||
$xmlWriter->endElement(); // w:r
|
$xmlWriter->endElement(); // w:r
|
||||||
$xmlWriter->endElement(); // w:sdtContent
|
$xmlWriter->endElement(); // w:sdtContent
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@ namespace PhpOffice\PhpWord\Writer\Word2007\Element;
|
||||||
|
|
||||||
use PhpOffice\Common\XMLWriter;
|
use PhpOffice\Common\XMLWriter;
|
||||||
use PhpOffice\PhpWord\Element\TOC as TOCElement;
|
use PhpOffice\PhpWord\Element\TOC as TOCElement;
|
||||||
|
use PhpOffice\PhpWord\Settings;
|
||||||
use PhpOffice\PhpWord\Style\Font;
|
use PhpOffice\PhpWord\Style\Font;
|
||||||
use PhpOffice\PhpWord\Writer\Word2007\Style\Font as FontStyleWriter;
|
use PhpOffice\PhpWord\Writer\Word2007\Style\Font as FontStyleWriter;
|
||||||
use PhpOffice\PhpWord\Writer\Word2007\Style\Paragraph as ParagraphStyleWriter;
|
use PhpOffice\PhpWord\Writer\Word2007\Style\Paragraph as ParagraphStyleWriter;
|
||||||
|
|
@ -99,9 +100,13 @@ class TOC extends AbstractElement
|
||||||
$styleWriter = new FontStyleWriter($xmlWriter, $fontStyle);
|
$styleWriter = new FontStyleWriter($xmlWriter, $fontStyle);
|
||||||
$styleWriter->write();
|
$styleWriter->write();
|
||||||
}
|
}
|
||||||
|
if (Settings::isOutputEscapingEnabled()) {
|
||||||
|
$xmlWriter->writeElement('w:t', $title->getText());
|
||||||
|
} else {
|
||||||
$xmlWriter->startElement('w:t');
|
$xmlWriter->startElement('w:t');
|
||||||
$xmlWriter->writeRaw($title->getText());
|
$xmlWriter->writeRaw($title->getText());
|
||||||
$xmlWriter->endElement();
|
$xmlWriter->endElement();
|
||||||
|
}
|
||||||
$xmlWriter->endElement(); // w:r
|
$xmlWriter->endElement(); // w:r
|
||||||
|
|
||||||
$xmlWriter->startElement('w:r');
|
$xmlWriter->startElement('w:r');
|
||||||
|
|
@ -117,7 +122,7 @@ class TOC extends AbstractElement
|
||||||
$xmlWriter->startElement('w:r');
|
$xmlWriter->startElement('w:r');
|
||||||
$xmlWriter->startElement('w:instrText');
|
$xmlWriter->startElement('w:instrText');
|
||||||
$xmlWriter->writeAttribute('xml:space', 'preserve');
|
$xmlWriter->writeAttribute('xml:space', 'preserve');
|
||||||
$xmlWriter->writeRaw("PAGEREF _Toc{$rId} \h");
|
$xmlWriter->text("PAGEREF _Toc{$rId} \h");
|
||||||
$xmlWriter->endElement();
|
$xmlWriter->endElement();
|
||||||
$xmlWriter->endElement();
|
$xmlWriter->endElement();
|
||||||
|
|
||||||
|
|
@ -200,7 +205,7 @@ class TOC extends AbstractElement
|
||||||
$xmlWriter->startElement('w:r');
|
$xmlWriter->startElement('w:r');
|
||||||
$xmlWriter->startElement('w:instrText');
|
$xmlWriter->startElement('w:instrText');
|
||||||
$xmlWriter->writeAttribute('xml:space', 'preserve');
|
$xmlWriter->writeAttribute('xml:space', 'preserve');
|
||||||
$xmlWriter->writeRaw("TOC \o {$minDepth}-{$maxDepth} \h \z \u");
|
$xmlWriter->text("TOC \o {$minDepth}-{$maxDepth} \h \z \u");
|
||||||
$xmlWriter->endElement();
|
$xmlWriter->endElement();
|
||||||
$xmlWriter->endElement();
|
$xmlWriter->endElement();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace PhpOffice\PhpWord\Writer\Word2007\Element;
|
namespace PhpOffice\PhpWord\Writer\Word2007\Element;
|
||||||
|
use PhpOffice\PhpWord\Settings;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Text element writer
|
* Text element writer
|
||||||
|
|
@ -45,7 +46,11 @@ class Text extends AbstractElement
|
||||||
|
|
||||||
$xmlWriter->startElement('w:t');
|
$xmlWriter->startElement('w:t');
|
||||||
$xmlWriter->writeAttribute('xml:space', 'preserve');
|
$xmlWriter->writeAttribute('xml:space', 'preserve');
|
||||||
|
if (Settings::isOutputEscapingEnabled()) {
|
||||||
|
$xmlWriter->text($this->getText($element->getText()));
|
||||||
|
} else {
|
||||||
$xmlWriter->writeRaw($this->getText($element->getText()));
|
$xmlWriter->writeRaw($this->getText($element->getText()));
|
||||||
|
}
|
||||||
$xmlWriter->endElement();
|
$xmlWriter->endElement();
|
||||||
$xmlWriter->endElement(); // w:r
|
$xmlWriter->endElement(); // w:r
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace PhpOffice\PhpWord\Writer\Word2007\Element;
|
namespace PhpOffice\PhpWord\Writer\Word2007\Element;
|
||||||
|
use PhpOffice\PhpWord\Settings;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TextRun element writer
|
* TextRun element writer
|
||||||
|
|
@ -60,9 +61,13 @@ class Title extends AbstractElement
|
||||||
|
|
||||||
// Actual text
|
// Actual text
|
||||||
$xmlWriter->startElement('w:r');
|
$xmlWriter->startElement('w:r');
|
||||||
|
if (Settings::isOutputEscapingEnabled()) {
|
||||||
|
$xmlWriter->writeElement('w:t', $this->getText($element->getText()));
|
||||||
|
} else {
|
||||||
$xmlWriter->startElement('w:t');
|
$xmlWriter->startElement('w:t');
|
||||||
$xmlWriter->writeRaw($this->getText($element->getText()));
|
$xmlWriter->writeRaw($this->getText($element->getText()));
|
||||||
$xmlWriter->endElement();
|
$xmlWriter->endElement();
|
||||||
|
}
|
||||||
$xmlWriter->endElement();
|
$xmlWriter->endElement();
|
||||||
|
|
||||||
// Bookmark end
|
// Bookmark end
|
||||||
|
|
|
||||||
|
|
@ -241,11 +241,13 @@ class Chart extends AbstractPart
|
||||||
foreach ($values as $value) {
|
foreach ($values as $value) {
|
||||||
$xmlWriter->startElement('c:pt');
|
$xmlWriter->startElement('c:pt');
|
||||||
$xmlWriter->writeAttribute('idx', $index);
|
$xmlWriter->writeAttribute('idx', $index);
|
||||||
|
if (\PhpOffice\PhpWord\Settings::isOutputEscapingEnabled()) {
|
||||||
|
$xmlWriter->writeElement('c:v', $value);
|
||||||
|
} else {
|
||||||
$xmlWriter->startElement('c:v');
|
$xmlWriter->startElement('c:v');
|
||||||
$xmlWriter->writeRaw($value);
|
$xmlWriter->writeRaw($value);
|
||||||
$xmlWriter->endElement(); // c:v
|
$xmlWriter->endElement();
|
||||||
|
}
|
||||||
$xmlWriter->endElement(); // c:pt
|
$xmlWriter->endElement(); // c:pt
|
||||||
$index++;
|
$index++;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -54,13 +54,13 @@ class DocPropsCore extends AbstractPart
|
||||||
// dcterms:created
|
// dcterms:created
|
||||||
$xmlWriter->startElement('dcterms:created');
|
$xmlWriter->startElement('dcterms:created');
|
||||||
$xmlWriter->writeAttribute('xsi:type', 'dcterms:W3CDTF');
|
$xmlWriter->writeAttribute('xsi:type', 'dcterms:W3CDTF');
|
||||||
$xmlWriter->writeRaw(date($this->dateFormat, $phpWord->getDocInfo()->getCreated()));
|
$xmlWriter->text(date($this->dateFormat, $phpWord->getDocInfo()->getCreated()));
|
||||||
$xmlWriter->endElement();
|
$xmlWriter->endElement();
|
||||||
|
|
||||||
// dcterms:modified
|
// dcterms:modified
|
||||||
$xmlWriter->startElement('dcterms:modified');
|
$xmlWriter->startElement('dcterms:modified');
|
||||||
$xmlWriter->writeAttribute('xsi:type', 'dcterms:W3CDTF');
|
$xmlWriter->writeAttribute('xsi:type', 'dcterms:W3CDTF');
|
||||||
$xmlWriter->writeRaw(date($this->dateFormat, $phpWord->getDocInfo()->getModified()));
|
$xmlWriter->text(date($this->dateFormat, $phpWord->getDocInfo()->getModified()));
|
||||||
$xmlWriter->endElement();
|
$xmlWriter->endElement();
|
||||||
|
|
||||||
$xmlWriter->endElement(); // cp:coreProperties
|
$xmlWriter->endElement(); // cp:coreProperties
|
||||||
|
|
|
||||||
|
|
@ -60,9 +60,7 @@ class DocPropsCustom extends AbstractPart
|
||||||
$xmlWriter->writeElement('vt:bool', ($propertyValue) ? 'true' : 'false');
|
$xmlWriter->writeElement('vt:bool', ($propertyValue) ? 'true' : 'false');
|
||||||
break;
|
break;
|
||||||
case 'd':
|
case 'd':
|
||||||
$xmlWriter->startElement('vt:filetime');
|
$xmlWriter->writeElement('vt:filetime', date($this->dateFormat, $propertyValue));
|
||||||
$xmlWriter->writeRaw(date($this->dateFormat, $propertyValue));
|
|
||||||
$xmlWriter->endElement();
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
$xmlWriter->writeElement('vt:lpwstr', $propertyValue);
|
$xmlWriter->writeElement('vt:lpwstr', $propertyValue);
|
||||||
|
|
|
||||||
|
|
@ -164,7 +164,7 @@ class Footnotes extends AbstractPart
|
||||||
$xmlWriter->startElement('w:r');
|
$xmlWriter->startElement('w:r');
|
||||||
$xmlWriter->startElement('w:t');
|
$xmlWriter->startElement('w:t');
|
||||||
$xmlWriter->writeAttribute('xml:space', 'preserve');
|
$xmlWriter->writeAttribute('xml:space', 'preserve');
|
||||||
$xmlWriter->writeRaw(' ');
|
$xmlWriter->text(' ');
|
||||||
$xmlWriter->endElement(); // w:t
|
$xmlWriter->endElement(); // w:t
|
||||||
$xmlWriter->endElement(); // w:r
|
$xmlWriter->endElement(); // w:r
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,7 @@ class CellTest extends \PHPUnit_Framework_TestCase
|
||||||
public function testAddText()
|
public function testAddText()
|
||||||
{
|
{
|
||||||
$oCell = new Cell();
|
$oCell = new Cell();
|
||||||
$element = $oCell->addText(htmlspecialchars('text', ENT_COMPAT, 'UTF-8'));
|
$element = $oCell->addText('text');
|
||||||
|
|
||||||
$this->assertCount(1, $oCell->getElements());
|
$this->assertCount(1, $oCell->getElements());
|
||||||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Text', $element);
|
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Text', $element);
|
||||||
|
|
@ -64,11 +64,11 @@ class CellTest extends \PHPUnit_Framework_TestCase
|
||||||
public function testAddTextNotUTF8()
|
public function testAddTextNotUTF8()
|
||||||
{
|
{
|
||||||
$oCell = new Cell();
|
$oCell = new Cell();
|
||||||
$element = $oCell->addText(utf8_decode(htmlspecialchars('ééé', ENT_COMPAT, 'UTF-8')));
|
$element = $oCell->addText(utf8_decode('ééé'));
|
||||||
|
|
||||||
$this->assertCount(1, $oCell->getElements());
|
$this->assertCount(1, $oCell->getElements());
|
||||||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Text', $element);
|
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Text', $element);
|
||||||
$this->assertEquals(htmlspecialchars('ééé', ENT_COMPAT, 'UTF-8'), $element->getText());
|
$this->assertEquals('ééé', $element->getText());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -77,7 +77,7 @@ class CellTest extends \PHPUnit_Framework_TestCase
|
||||||
public function testAddLink()
|
public function testAddLink()
|
||||||
{
|
{
|
||||||
$oCell = new Cell();
|
$oCell = new Cell();
|
||||||
$element = $oCell->addLink(utf8_decode('ééé'), utf8_decode(htmlspecialchars('ééé', ENT_COMPAT, 'UTF-8')));
|
$element = $oCell->addLink(utf8_decode('ééé'), utf8_decode('ééé'));
|
||||||
|
|
||||||
$this->assertCount(1, $oCell->getElements());
|
$this->assertCount(1, $oCell->getElements());
|
||||||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Link', $element);
|
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Link', $element);
|
||||||
|
|
@ -100,11 +100,11 @@ class CellTest extends \PHPUnit_Framework_TestCase
|
||||||
public function testAddListItem()
|
public function testAddListItem()
|
||||||
{
|
{
|
||||||
$oCell = new Cell();
|
$oCell = new Cell();
|
||||||
$element = $oCell->addListItem(htmlspecialchars('text', ENT_COMPAT, 'UTF-8'));
|
$element = $oCell->addListItem('text');
|
||||||
|
|
||||||
$this->assertCount(1, $oCell->getElements());
|
$this->assertCount(1, $oCell->getElements());
|
||||||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\ListItem', $element);
|
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\ListItem', $element);
|
||||||
$this->assertEquals(htmlspecialchars('text', ENT_COMPAT, 'UTF-8'), $element->getTextObject()->getText());
|
$this->assertEquals('text', $element->getTextObject()->getText());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -113,11 +113,11 @@ class CellTest extends \PHPUnit_Framework_TestCase
|
||||||
public function testAddListItemNotUTF8()
|
public function testAddListItemNotUTF8()
|
||||||
{
|
{
|
||||||
$oCell = new Cell();
|
$oCell = new Cell();
|
||||||
$element = $oCell->addListItem(utf8_decode(htmlspecialchars('ééé', ENT_COMPAT, 'UTF-8')));
|
$element = $oCell->addListItem(utf8_decode('ééé'));
|
||||||
|
|
||||||
$this->assertCount(1, $oCell->getElements());
|
$this->assertCount(1, $oCell->getElements());
|
||||||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\ListItem', $element);
|
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\ListItem', $element);
|
||||||
$this->assertEquals(htmlspecialchars('ééé', ENT_COMPAT, 'UTF-8'), $element->getTextObject()->getText());
|
$this->assertEquals('ééé', $element->getTextObject()->getText());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -165,9 +165,7 @@ class CellTest extends \PHPUnit_Framework_TestCase
|
||||||
public function testAddImageSectionByUrl()
|
public function testAddImageSectionByUrl()
|
||||||
{
|
{
|
||||||
$oCell = new Cell();
|
$oCell = new Cell();
|
||||||
$element = $oCell->addImage(
|
$element = $oCell->addImage('http://php.net/images/logos/php-med-trans-light.gif');
|
||||||
'http://php.net/images/logos/php-med-trans-light.gif'
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->assertCount(1, $oCell->getElements());
|
$this->assertCount(1, $oCell->getElements());
|
||||||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Image', $element);
|
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Image', $element);
|
||||||
|
|
@ -205,7 +203,7 @@ class CellTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
$oCell = new Cell();
|
$oCell = new Cell();
|
||||||
$oCell->setDocPart('Header', 1);
|
$oCell->setDocPart('Header', 1);
|
||||||
$element = $oCell->addPreserveText(htmlspecialchars('text', ENT_COMPAT, 'UTF-8'));
|
$element = $oCell->addPreserveText('text');
|
||||||
|
|
||||||
$this->assertCount(1, $oCell->getElements());
|
$this->assertCount(1, $oCell->getElements());
|
||||||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\PreserveText', $element);
|
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\PreserveText', $element);
|
||||||
|
|
@ -218,11 +216,11 @@ class CellTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
$oCell = new Cell();
|
$oCell = new Cell();
|
||||||
$oCell->setDocPart('Header', 1);
|
$oCell->setDocPart('Header', 1);
|
||||||
$element = $oCell->addPreserveText(utf8_decode(htmlspecialchars('ééé', ENT_COMPAT, 'UTF-8')));
|
$element = $oCell->addPreserveText(utf8_decode('ééé'));
|
||||||
|
|
||||||
$this->assertCount(1, $oCell->getElements());
|
$this->assertCount(1, $oCell->getElements());
|
||||||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\PreserveText', $element);
|
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\PreserveText', $element);
|
||||||
$this->assertEquals(array(htmlspecialchars('ééé', ENT_COMPAT, 'UTF-8')), $element->getText());
|
$this->assertEquals(array('ééé'), $element->getText());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -234,7 +232,7 @@ class CellTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
$oCell = new Cell();
|
$oCell = new Cell();
|
||||||
$oCell->setDocPart('Section', 1);
|
$oCell->setDocPart('Section', 1);
|
||||||
$oCell->addPreserveText(htmlspecialchars('text', ENT_COMPAT, 'UTF-8'));
|
$oCell->addPreserveText('text');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -255,7 +253,7 @@ class CellTest extends \PHPUnit_Framework_TestCase
|
||||||
public function testAddCheckBox()
|
public function testAddCheckBox()
|
||||||
{
|
{
|
||||||
$oCell = new Cell();
|
$oCell = new Cell();
|
||||||
$element = $oCell->addCheckBox(utf8_decode(htmlspecialchars('ééé', ENT_COMPAT, 'UTF-8')), utf8_decode(htmlspecialchars('ééé', ENT_COMPAT, 'UTF-8')));
|
$element = $oCell->addCheckBox(utf8_decode('ééé'), utf8_decode('ééé'));
|
||||||
|
|
||||||
$this->assertCount(1, $oCell->getElements());
|
$this->assertCount(1, $oCell->getElements());
|
||||||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\CheckBox', $element);
|
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\CheckBox', $element);
|
||||||
|
|
|
||||||
|
|
@ -45,10 +45,10 @@ class CheckBoxTest extends \PHPUnit_Framework_TestCase
|
||||||
*/
|
*/
|
||||||
public function testCheckBox()
|
public function testCheckBox()
|
||||||
{
|
{
|
||||||
$oCheckBox = new CheckBox(htmlspecialchars('chkBox', ENT_COMPAT, 'UTF-8'), htmlspecialchars('CheckBox', ENT_COMPAT, 'UTF-8'));
|
$oCheckBox = new CheckBox('chkBox', 'CheckBox');
|
||||||
|
|
||||||
$this->assertEquals(htmlspecialchars('chkBox', ENT_COMPAT, 'UTF-8'), $oCheckBox->getName());
|
$this->assertEquals('chkBox', $oCheckBox->getName());
|
||||||
$this->assertEquals(htmlspecialchars('CheckBox', ENT_COMPAT, 'UTF-8'), $oCheckBox->getText());
|
$this->assertEquals('CheckBox', $oCheckBox->getText());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -56,7 +56,7 @@ class CheckBoxTest extends \PHPUnit_Framework_TestCase
|
||||||
*/
|
*/
|
||||||
public function testFont()
|
public function testFont()
|
||||||
{
|
{
|
||||||
$oCheckBox = new CheckBox(htmlspecialchars('chkBox', ENT_COMPAT, 'UTF-8'), htmlspecialchars('CheckBox', ENT_COMPAT, 'UTF-8'), 'fontStyle');
|
$oCheckBox = new CheckBox('chkBox', 'CheckBox', 'fontStyle');
|
||||||
$this->assertEquals('fontStyle', $oCheckBox->getFontStyle());
|
$this->assertEquals('fontStyle', $oCheckBox->getFontStyle());
|
||||||
|
|
||||||
$oCheckBox->setFontStyle(array('bold' => true, 'italic' => true, 'size' => 16));
|
$oCheckBox->setFontStyle(array('bold' => true, 'italic' => true, 'size' => 16));
|
||||||
|
|
@ -69,7 +69,7 @@ class CheckBoxTest extends \PHPUnit_Framework_TestCase
|
||||||
public function testFontObject()
|
public function testFontObject()
|
||||||
{
|
{
|
||||||
$font = new Font();
|
$font = new Font();
|
||||||
$oCheckBox = new CheckBox(htmlspecialchars('chkBox', ENT_COMPAT, 'UTF-8'), htmlspecialchars('CheckBox', ENT_COMPAT, 'UTF-8'), $font);
|
$oCheckBox = new CheckBox('chkBox', 'CheckBox', $font);
|
||||||
$this->assertEquals($font, $oCheckBox->getFontStyle());
|
$this->assertEquals($font, $oCheckBox->getFontStyle());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -78,7 +78,7 @@ class CheckBoxTest extends \PHPUnit_Framework_TestCase
|
||||||
*/
|
*/
|
||||||
public function testParagraph()
|
public function testParagraph()
|
||||||
{
|
{
|
||||||
$oCheckBox = new CheckBox(htmlspecialchars('chkBox', ENT_COMPAT, 'UTF-8'), htmlspecialchars('CheckBox', ENT_COMPAT, 'UTF-8'), 'fontStyle', 'paragraphStyle');
|
$oCheckBox = new CheckBox('chkBox', 'CheckBox', 'fontStyle', 'paragraphStyle');
|
||||||
$this->assertEquals('paragraphStyle', $oCheckBox->getParagraphStyle());
|
$this->assertEquals('paragraphStyle', $oCheckBox->getParagraphStyle());
|
||||||
|
|
||||||
$oCheckBox->setParagraphStyle(array('alignment' => Jc::CENTER, 'spaceAfter' => 100));
|
$oCheckBox->setParagraphStyle(array('alignment' => Jc::CENTER, 'spaceAfter' => 100));
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,7 @@ class FooterTest extends \PHPUnit_Framework_TestCase
|
||||||
public function testAddText()
|
public function testAddText()
|
||||||
{
|
{
|
||||||
$oFooter = new Footer(1);
|
$oFooter = new Footer(1);
|
||||||
$element = $oFooter->addText(htmlspecialchars('text', ENT_COMPAT, 'UTF-8'));
|
$element = $oFooter->addText('text');
|
||||||
|
|
||||||
$this->assertCount(1, $oFooter->getElements());
|
$this->assertCount(1, $oFooter->getElements());
|
||||||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Text', $element);
|
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Text', $element);
|
||||||
|
|
@ -54,11 +54,11 @@ class FooterTest extends \PHPUnit_Framework_TestCase
|
||||||
public function testAddTextNotUTF8()
|
public function testAddTextNotUTF8()
|
||||||
{
|
{
|
||||||
$oFooter = new Footer(1);
|
$oFooter = new Footer(1);
|
||||||
$element = $oFooter->addText(utf8_decode(htmlspecialchars('ééé', ENT_COMPAT, 'UTF-8')));
|
$element = $oFooter->addText(utf8_decode('ééé'));
|
||||||
|
|
||||||
$this->assertCount(1, $oFooter->getElements());
|
$this->assertCount(1, $oFooter->getElements());
|
||||||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Text', $element);
|
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Text', $element);
|
||||||
$this->assertEquals(htmlspecialchars('ééé', ENT_COMPAT, 'UTF-8'), $element->getText());
|
$this->assertEquals('ééé', $element->getText());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -116,9 +116,7 @@ class FooterTest extends \PHPUnit_Framework_TestCase
|
||||||
public function testAddImageByUrl()
|
public function testAddImageByUrl()
|
||||||
{
|
{
|
||||||
$oFooter = new Footer(1);
|
$oFooter = new Footer(1);
|
||||||
$element = $oFooter->addImage(
|
$element = $oFooter->addImage('http://php.net/images/logos/php-med-trans-light.gif');
|
||||||
'http://php.net/images/logos/php-med-trans-light.gif'
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->assertCount(1, $oFooter->getElements());
|
$this->assertCount(1, $oFooter->getElements());
|
||||||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Image', $element);
|
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Image', $element);
|
||||||
|
|
@ -130,7 +128,7 @@ class FooterTest extends \PHPUnit_Framework_TestCase
|
||||||
public function testAddPreserveText()
|
public function testAddPreserveText()
|
||||||
{
|
{
|
||||||
$oFooter = new Footer(1);
|
$oFooter = new Footer(1);
|
||||||
$element = $oFooter->addPreserveText(htmlspecialchars('text', ENT_COMPAT, 'UTF-8'));
|
$element = $oFooter->addPreserveText('text');
|
||||||
|
|
||||||
$this->assertCount(1, $oFooter->getElements());
|
$this->assertCount(1, $oFooter->getElements());
|
||||||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\PreserveText', $element);
|
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\PreserveText', $element);
|
||||||
|
|
@ -142,11 +140,11 @@ class FooterTest extends \PHPUnit_Framework_TestCase
|
||||||
public function testAddPreserveTextNotUTF8()
|
public function testAddPreserveTextNotUTF8()
|
||||||
{
|
{
|
||||||
$oFooter = new Footer(1);
|
$oFooter = new Footer(1);
|
||||||
$element = $oFooter->addPreserveText(utf8_decode(htmlspecialchars('ééé', ENT_COMPAT, 'UTF-8')));
|
$element = $oFooter->addPreserveText(utf8_decode('ééé'));
|
||||||
|
|
||||||
$this->assertCount(1, $oFooter->getElements());
|
$this->assertCount(1, $oFooter->getElements());
|
||||||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\PreserveText', $element);
|
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\PreserveText', $element);
|
||||||
$this->assertEquals(array(htmlspecialchars('ééé', ENT_COMPAT, 'UTF-8')), $element->getText());
|
$this->assertEquals(array('ééé'), $element->getText());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -65,7 +65,7 @@ class FootnoteTest extends \PHPUnit_Framework_TestCase
|
||||||
public function testAddText()
|
public function testAddText()
|
||||||
{
|
{
|
||||||
$oFootnote = new Footnote();
|
$oFootnote = new Footnote();
|
||||||
$element = $oFootnote->addText(htmlspecialchars('text', ENT_COMPAT, 'UTF-8'));
|
$element = $oFootnote->addText('text');
|
||||||
|
|
||||||
$this->assertCount(1, $oFootnote->getElements());
|
$this->assertCount(1, $oFootnote->getElements());
|
||||||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Text', $element);
|
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Text', $element);
|
||||||
|
|
|
||||||
|
|
@ -43,11 +43,11 @@ class HeaderTest extends \PHPUnit_Framework_TestCase
|
||||||
public function testAddText()
|
public function testAddText()
|
||||||
{
|
{
|
||||||
$oHeader = new Header(1);
|
$oHeader = new Header(1);
|
||||||
$element = $oHeader->addText(htmlspecialchars('text', ENT_COMPAT, 'UTF-8'));
|
$element = $oHeader->addText('text');
|
||||||
|
|
||||||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Text', $element);
|
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Text', $element);
|
||||||
$this->assertCount(1, $oHeader->getElements());
|
$this->assertCount(1, $oHeader->getElements());
|
||||||
$this->assertEquals(htmlspecialchars('text', ENT_COMPAT, 'UTF-8'), $element->getText());
|
$this->assertEquals('text', $element->getText());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -56,11 +56,11 @@ class HeaderTest extends \PHPUnit_Framework_TestCase
|
||||||
public function testAddTextNotUTF8()
|
public function testAddTextNotUTF8()
|
||||||
{
|
{
|
||||||
$oHeader = new Header(1);
|
$oHeader = new Header(1);
|
||||||
$element = $oHeader->addText(utf8_decode(htmlspecialchars('ééé', ENT_COMPAT, 'UTF-8')));
|
$element = $oHeader->addText(utf8_decode('ééé'));
|
||||||
|
|
||||||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Text', $element);
|
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Text', $element);
|
||||||
$this->assertCount(1, $oHeader->getElements());
|
$this->assertCount(1, $oHeader->getElements());
|
||||||
$this->assertEquals(htmlspecialchars('ééé', ENT_COMPAT, 'UTF-8'), $element->getText());
|
$this->assertEquals('ééé', $element->getText());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -125,9 +125,7 @@ class HeaderTest extends \PHPUnit_Framework_TestCase
|
||||||
public function testAddImageByUrl()
|
public function testAddImageByUrl()
|
||||||
{
|
{
|
||||||
$oHeader = new Header(1);
|
$oHeader = new Header(1);
|
||||||
$element = $oHeader->addImage(
|
$element = $oHeader->addImage('http://php.net/images/logos/php-med-trans-light.gif');
|
||||||
'http://php.net/images/logos/php-med-trans-light.gif'
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->assertCount(1, $oHeader->getElements());
|
$this->assertCount(1, $oHeader->getElements());
|
||||||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Image', $element);
|
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Image', $element);
|
||||||
|
|
@ -139,7 +137,7 @@ class HeaderTest extends \PHPUnit_Framework_TestCase
|
||||||
public function testAddPreserveText()
|
public function testAddPreserveText()
|
||||||
{
|
{
|
||||||
$oHeader = new Header(1);
|
$oHeader = new Header(1);
|
||||||
$element = $oHeader->addPreserveText(htmlspecialchars('text', ENT_COMPAT, 'UTF-8'));
|
$element = $oHeader->addPreserveText('text');
|
||||||
|
|
||||||
$this->assertCount(1, $oHeader->getElements());
|
$this->assertCount(1, $oHeader->getElements());
|
||||||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\PreserveText', $element);
|
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\PreserveText', $element);
|
||||||
|
|
@ -151,11 +149,11 @@ class HeaderTest extends \PHPUnit_Framework_TestCase
|
||||||
public function testAddPreserveTextNotUTF8()
|
public function testAddPreserveTextNotUTF8()
|
||||||
{
|
{
|
||||||
$oHeader = new Header(1);
|
$oHeader = new Header(1);
|
||||||
$element = $oHeader->addPreserveText(utf8_decode(htmlspecialchars('ééé', ENT_COMPAT, 'UTF-8')));
|
$element = $oHeader->addPreserveText(utf8_decode('ééé'));
|
||||||
|
|
||||||
$this->assertCount(1, $oHeader->getElements());
|
$this->assertCount(1, $oHeader->getElements());
|
||||||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\PreserveText', $element);
|
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\PreserveText', $element);
|
||||||
$this->assertEquals(array(htmlspecialchars('ééé', ENT_COMPAT, 'UTF-8')), $element->getText());
|
$this->assertEquals(array('ééé'), $element->getText());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -48,14 +48,14 @@ class LinkTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
$oLink = new Link(
|
$oLink = new Link(
|
||||||
'https://github.com/PHPOffice/PHPWord',
|
'https://github.com/PHPOffice/PHPWord',
|
||||||
htmlspecialchars('PHPWord on GitHub', ENT_COMPAT, 'UTF-8'),
|
'PHPWord on GitHub',
|
||||||
array('color' => '0000FF', 'underline' => Font::UNDERLINE_SINGLE),
|
array('color' => '0000FF', 'underline' => Font::UNDERLINE_SINGLE),
|
||||||
array('marginLeft' => 600, 'marginRight' => 600, 'marginTop' => 600, 'marginBottom' => 600)
|
array('marginLeft' => 600, 'marginRight' => 600, 'marginTop' => 600, 'marginBottom' => 600)
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Link', $oLink);
|
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Link', $oLink);
|
||||||
$this->assertEquals('https://github.com/PHPOffice/PHPWord', $oLink->getSource());
|
$this->assertEquals('https://github.com/PHPOffice/PHPWord', $oLink->getSource());
|
||||||
$this->assertEquals(htmlspecialchars('PHPWord on GitHub', ENT_COMPAT, 'UTF-8'), $oLink->getText());
|
$this->assertEquals('PHPWord on GitHub', $oLink->getText());
|
||||||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Font', $oLink->getFontStyle());
|
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Font', $oLink->getFontStyle());
|
||||||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Paragraph', $oLink->getParagraphStyle());
|
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Paragraph', $oLink->getParagraphStyle());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -99,11 +99,11 @@ class ListItemRunTest extends \PHPUnit_Framework_TestCase
|
||||||
public function testAddText()
|
public function testAddText()
|
||||||
{
|
{
|
||||||
$oListItemRun = new ListItemRun();
|
$oListItemRun = new ListItemRun();
|
||||||
$element = $oListItemRun->addText(htmlspecialchars('text', ENT_COMPAT, 'UTF-8'));
|
$element = $oListItemRun->addText('text');
|
||||||
|
|
||||||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Text', $element);
|
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Text', $element);
|
||||||
$this->assertCount(1, $oListItemRun->getElements());
|
$this->assertCount(1, $oListItemRun->getElements());
|
||||||
$this->assertEquals(htmlspecialchars('text', ENT_COMPAT, 'UTF-8'), $element->getText());
|
$this->assertEquals('text', $element->getText());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -112,11 +112,11 @@ class ListItemRunTest extends \PHPUnit_Framework_TestCase
|
||||||
public function testAddTextNotUTF8()
|
public function testAddTextNotUTF8()
|
||||||
{
|
{
|
||||||
$oListItemRun = new ListItemRun();
|
$oListItemRun = new ListItemRun();
|
||||||
$element = $oListItemRun->addText(utf8_decode(htmlspecialchars('ééé', ENT_COMPAT, 'UTF-8')));
|
$element = $oListItemRun->addText(utf8_decode('ééé'));
|
||||||
|
|
||||||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Text', $element);
|
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Text', $element);
|
||||||
$this->assertCount(1, $oListItemRun->getElements());
|
$this->assertCount(1, $oListItemRun->getElements());
|
||||||
$this->assertEquals(htmlspecialchars('ééé', ENT_COMPAT, 'UTF-8'), $element->getText());
|
$this->assertEquals('ééé', $element->getText());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -138,12 +138,12 @@ class ListItemRunTest extends \PHPUnit_Framework_TestCase
|
||||||
public function testAddLinkWithName()
|
public function testAddLinkWithName()
|
||||||
{
|
{
|
||||||
$oListItemRun = new ListItemRun();
|
$oListItemRun = new ListItemRun();
|
||||||
$element = $oListItemRun->addLink('https://github.com/PHPOffice/PHPWord', htmlspecialchars('PHPWord on GitHub', ENT_COMPAT, 'UTF-8'));
|
$element = $oListItemRun->addLink('https://github.com/PHPOffice/PHPWord', 'PHPWord on GitHub');
|
||||||
|
|
||||||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Link', $element);
|
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Link', $element);
|
||||||
$this->assertCount(1, $oListItemRun->getElements());
|
$this->assertCount(1, $oListItemRun->getElements());
|
||||||
$this->assertEquals('https://github.com/PHPOffice/PHPWord', $element->getSource());
|
$this->assertEquals('https://github.com/PHPOffice/PHPWord', $element->getSource());
|
||||||
$this->assertEquals(htmlspecialchars('PHPWord on GitHub', ENT_COMPAT, 'UTF-8'), $element->getText());
|
$this->assertEquals('PHPWord on GitHub', $element->getText());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ class ListItemTest extends \PHPUnit_Framework_TestCase
|
||||||
*/
|
*/
|
||||||
public function testText()
|
public function testText()
|
||||||
{
|
{
|
||||||
$oListItem = new ListItem(htmlspecialchars('text', ENT_COMPAT, 'UTF-8'));
|
$oListItem = new ListItem('text');
|
||||||
|
|
||||||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Text', $oListItem->getTextObject());
|
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Text', $oListItem->getTextObject());
|
||||||
}
|
}
|
||||||
|
|
@ -40,12 +40,7 @@ class ListItemTest extends \PHPUnit_Framework_TestCase
|
||||||
*/
|
*/
|
||||||
public function testStyle()
|
public function testStyle()
|
||||||
{
|
{
|
||||||
$oListItem = new ListItem(
|
$oListItem = new ListItem('text', 1, null, array('listType' => \PhpOffice\PhpWord\Style\ListItem::TYPE_NUMBER));
|
||||||
htmlspecialchars('text', ENT_COMPAT, 'UTF-8'),
|
|
||||||
1,
|
|
||||||
null,
|
|
||||||
array('listType' => \PhpOffice\PhpWord\Style\ListItem::TYPE_NUMBER)
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\ListItem', $oListItem->getStyle());
|
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\ListItem', $oListItem->getStyle());
|
||||||
$this->assertEquals(\PhpOffice\PhpWord\Style\ListItem::TYPE_NUMBER, $oListItem->getStyle()->getListType());
|
$this->assertEquals(\PhpOffice\PhpWord\Style\ListItem::TYPE_NUMBER, $oListItem->getStyle()->getListType());
|
||||||
|
|
@ -57,7 +52,7 @@ class ListItemTest extends \PHPUnit_Framework_TestCase
|
||||||
public function testDepth()
|
public function testDepth()
|
||||||
{
|
{
|
||||||
$iVal = rand(1, 1000);
|
$iVal = rand(1, 1000);
|
||||||
$oListItem = new ListItem(htmlspecialchars('text', ENT_COMPAT, 'UTF-8'), $iVal);
|
$oListItem = new ListItem('text', $iVal);
|
||||||
|
|
||||||
$this->assertEquals($iVal, $oListItem->getDepth());
|
$this->assertEquals($iVal, $oListItem->getDepth());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -44,8 +44,8 @@ class PreserveTextTest extends \PHPUnit_Framework_TestCase
|
||||||
*/
|
*/
|
||||||
public function testConstructWithString()
|
public function testConstructWithString()
|
||||||
{
|
{
|
||||||
$oPreserveText = new PreserveText(htmlspecialchars('text', ENT_COMPAT, 'UTF-8'), 'styleFont', 'styleParagraph');
|
$oPreserveText = new PreserveText('text', 'styleFont', 'styleParagraph');
|
||||||
$this->assertEquals(array(htmlspecialchars('text', ENT_COMPAT, 'UTF-8')), $oPreserveText->getText());
|
$this->assertEquals(array('text'), $oPreserveText->getText());
|
||||||
$this->assertEquals('styleFont', $oPreserveText->getFontStyle());
|
$this->assertEquals('styleFont', $oPreserveText->getFontStyle());
|
||||||
$this->assertEquals('styleParagraph', $oPreserveText->getParagraphStyle());
|
$this->assertEquals('styleParagraph', $oPreserveText->getParagraphStyle());
|
||||||
}
|
}
|
||||||
|
|
@ -55,11 +55,7 @@ class PreserveTextTest extends \PHPUnit_Framework_TestCase
|
||||||
*/
|
*/
|
||||||
public function testConstructWithArray()
|
public function testConstructWithArray()
|
||||||
{
|
{
|
||||||
$oPreserveText = new PreserveText(
|
$oPreserveText = new PreserveText('text', array('size' => 16, 'color' => '1B2232'), array('alignment' => Jc::CENTER));
|
||||||
htmlspecialchars('text', ENT_COMPAT, 'UTF-8'),
|
|
||||||
array('size' => 16, 'color' => '1B2232'),
|
|
||||||
array('alignment' => Jc::CENTER)
|
|
||||||
);
|
|
||||||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Font', $oPreserveText->getFontStyle());
|
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Font', $oPreserveText->getFontStyle());
|
||||||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Paragraph', $oPreserveText->getParagraphStyle());
|
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Paragraph', $oPreserveText->getParagraphStyle());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -48,18 +48,18 @@ class SectionTest extends \PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
$section = new Section(0);
|
$section = new Section(0);
|
||||||
$section->setPhpWord(new PhpWord());
|
$section->setPhpWord(new PhpWord());
|
||||||
$section->addText(utf8_decode(htmlspecialchars('ä', ENT_COMPAT, 'UTF-8')));
|
$section->addText(utf8_decode('ä'));
|
||||||
$section->addLink(utf8_decode('http://äää.com'), utf8_decode(htmlspecialchars('ä', ENT_COMPAT, 'UTF-8')));
|
$section->addLink(utf8_decode('http://äää.com'), utf8_decode('ä'));
|
||||||
$section->addTextBreak();
|
$section->addTextBreak();
|
||||||
$section->addPageBreak();
|
$section->addPageBreak();
|
||||||
$section->addTable();
|
$section->addTable();
|
||||||
$section->addListItem(utf8_decode(htmlspecialchars('ä', ENT_COMPAT, 'UTF-8')));
|
$section->addListItem(utf8_decode('ä'));
|
||||||
$section->addObject($objectSource);
|
$section->addObject($objectSource);
|
||||||
$section->addImage($imageSource);
|
$section->addImage($imageSource);
|
||||||
$section->addTitle(utf8_decode(htmlspecialchars('ä', ENT_COMPAT, 'UTF-8')), 1);
|
$section->addTitle(utf8_decode('ä'), 1);
|
||||||
$section->addTextRun();
|
$section->addTextRun();
|
||||||
$section->addFootnote();
|
$section->addFootnote();
|
||||||
$section->addCheckBox(utf8_decode(htmlspecialchars('chkä', ENT_COMPAT, 'UTF-8')), utf8_decode(htmlspecialchars('Contentä', ENT_COMPAT, 'UTF-8')));
|
$section->addCheckBox(utf8_decode('chkä'), utf8_decode('Contentä'));
|
||||||
$section->addTOC();
|
$section->addTOC();
|
||||||
|
|
||||||
$elementCollection = $section->getElements();
|
$elementCollection = $section->getElements();
|
||||||
|
|
@ -106,7 +106,7 @@ class SectionTest extends \PHPUnit_Framework_TestCase
|
||||||
Style::addTitleStyle(1, array('size' => 14));
|
Style::addTitleStyle(1, array('size' => 14));
|
||||||
$section = new Section(0);
|
$section = new Section(0);
|
||||||
$section->setPhpWord(new PhpWord());
|
$section->setPhpWord(new PhpWord());
|
||||||
$section->addTitle(htmlspecialchars('Test', ENT_COMPAT, 'UTF-8'), 1);
|
$section->addTitle('Test', 1);
|
||||||
$elementCollection = $section->getElements();
|
$elementCollection = $section->getElements();
|
||||||
|
|
||||||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Title', $elementCollection[0]);
|
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Title', $elementCollection[0]);
|
||||||
|
|
|
||||||
|
|
@ -84,7 +84,7 @@ class TOCTest extends \PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
$phpWord = new PhpWord();
|
$phpWord = new PhpWord();
|
||||||
foreach ($titles as $text => $depth) {
|
foreach ($titles as $text => $depth) {
|
||||||
$phpWord->addTitle(new Title(htmlspecialchars($text, ENT_COMPAT, 'UTF-8'), $depth));
|
$phpWord->addTitle(new Title($text, $depth));
|
||||||
}
|
}
|
||||||
$toc = new TOC();
|
$toc = new TOC();
|
||||||
$toc->setPhpWord($phpWord);
|
$toc->setPhpWord($phpWord);
|
||||||
|
|
|
||||||
|
|
@ -68,11 +68,11 @@ class TextRunTest extends \PHPUnit_Framework_TestCase
|
||||||
public function testAddText()
|
public function testAddText()
|
||||||
{
|
{
|
||||||
$oTextRun = new TextRun();
|
$oTextRun = new TextRun();
|
||||||
$element = $oTextRun->addText(htmlspecialchars('text', ENT_COMPAT, 'UTF-8'));
|
$element = $oTextRun->addText('text');
|
||||||
|
|
||||||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Text', $element);
|
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Text', $element);
|
||||||
$this->assertCount(1, $oTextRun->getElements());
|
$this->assertCount(1, $oTextRun->getElements());
|
||||||
$this->assertEquals(htmlspecialchars('text', ENT_COMPAT, 'UTF-8'), $element->getText());
|
$this->assertEquals('text', $element->getText());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -81,11 +81,11 @@ class TextRunTest extends \PHPUnit_Framework_TestCase
|
||||||
public function testAddTextNotUTF8()
|
public function testAddTextNotUTF8()
|
||||||
{
|
{
|
||||||
$oTextRun = new TextRun();
|
$oTextRun = new TextRun();
|
||||||
$element = $oTextRun->addText(utf8_decode(htmlspecialchars('ééé', ENT_COMPAT, 'UTF-8')));
|
$element = $oTextRun->addText(utf8_decode('ééé'));
|
||||||
|
|
||||||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Text', $element);
|
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Text', $element);
|
||||||
$this->assertCount(1, $oTextRun->getElements());
|
$this->assertCount(1, $oTextRun->getElements());
|
||||||
$this->assertEquals(htmlspecialchars('ééé', ENT_COMPAT, 'UTF-8'), $element->getText());
|
$this->assertEquals('ééé', $element->getText());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -107,12 +107,12 @@ class TextRunTest extends \PHPUnit_Framework_TestCase
|
||||||
public function testAddLinkWithName()
|
public function testAddLinkWithName()
|
||||||
{
|
{
|
||||||
$oTextRun = new TextRun();
|
$oTextRun = new TextRun();
|
||||||
$element = $oTextRun->addLink('https://github.com/PHPOffice/PHPWord', htmlspecialchars('PHPWord on GitHub', ENT_COMPAT, 'UTF-8'));
|
$element = $oTextRun->addLink('https://github.com/PHPOffice/PHPWord', 'PHPWord on GitHub');
|
||||||
|
|
||||||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Link', $element);
|
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Link', $element);
|
||||||
$this->assertCount(1, $oTextRun->getElements());
|
$this->assertCount(1, $oTextRun->getElements());
|
||||||
$this->assertEquals('https://github.com/PHPOffice/PHPWord', $element->getSource());
|
$this->assertEquals('https://github.com/PHPOffice/PHPWord', $element->getSource());
|
||||||
$this->assertEquals(htmlspecialchars('PHPWord on GitHub', ENT_COMPAT, 'UTF-8'), $element->getText());
|
$this->assertEquals('PHPWord on GitHub', $element->getText());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -45,9 +45,9 @@ class TextTest extends \PHPUnit_Framework_TestCase
|
||||||
*/
|
*/
|
||||||
public function testText()
|
public function testText()
|
||||||
{
|
{
|
||||||
$oText = new Text(htmlspecialchars('text', ENT_COMPAT, 'UTF-8'));
|
$oText = new Text('text');
|
||||||
|
|
||||||
$this->assertEquals(htmlspecialchars('text', ENT_COMPAT, 'UTF-8'), $oText->getText());
|
$this->assertEquals('text', $oText->getText());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -55,7 +55,7 @@ class TextTest extends \PHPUnit_Framework_TestCase
|
||||||
*/
|
*/
|
||||||
public function testFont()
|
public function testFont()
|
||||||
{
|
{
|
||||||
$oText = new Text(htmlspecialchars('text', ENT_COMPAT, 'UTF-8'), 'fontStyle');
|
$oText = new Text('text', 'fontStyle');
|
||||||
$this->assertEquals('fontStyle', $oText->getFontStyle());
|
$this->assertEquals('fontStyle', $oText->getFontStyle());
|
||||||
|
|
||||||
$oText->setFontStyle(array('bold' => true, 'italic' => true, 'size' => 16));
|
$oText->setFontStyle(array('bold' => true, 'italic' => true, 'size' => 16));
|
||||||
|
|
@ -68,7 +68,7 @@ class TextTest extends \PHPUnit_Framework_TestCase
|
||||||
public function testFontObject()
|
public function testFontObject()
|
||||||
{
|
{
|
||||||
$font = new Font();
|
$font = new Font();
|
||||||
$oText = new Text(htmlspecialchars('text', ENT_COMPAT, 'UTF-8'), $font);
|
$oText = new Text('text', $font);
|
||||||
$this->assertEquals($font, $oText->getFontStyle());
|
$this->assertEquals($font, $oText->getFontStyle());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -77,7 +77,7 @@ class TextTest extends \PHPUnit_Framework_TestCase
|
||||||
*/
|
*/
|
||||||
public function testParagraph()
|
public function testParagraph()
|
||||||
{
|
{
|
||||||
$oText = new Text(htmlspecialchars('text', ENT_COMPAT, 'UTF-8'), 'fontStyle', 'paragraphStyle');
|
$oText = new Text('text', 'fontStyle', 'paragraphStyle');
|
||||||
$this->assertEquals('paragraphStyle', $oText->getParagraphStyle());
|
$this->assertEquals('paragraphStyle', $oText->getParagraphStyle());
|
||||||
|
|
||||||
$oText->setParagraphStyle(array('alignment' => Jc::CENTER, 'spaceAfter' => 100));
|
$oText->setParagraphStyle(array('alignment' => Jc::CENTER, 'spaceAfter' => 100));
|
||||||
|
|
|
||||||
|
|
@ -30,10 +30,10 @@ class TitleTest extends \PHPUnit_Framework_TestCase
|
||||||
*/
|
*/
|
||||||
public function testConstruct()
|
public function testConstruct()
|
||||||
{
|
{
|
||||||
$oTitle = new Title(htmlspecialchars('text', ENT_COMPAT, 'UTF-8'));
|
$oTitle = new Title('text');
|
||||||
|
|
||||||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Title', $oTitle);
|
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Title', $oTitle);
|
||||||
$this->assertEquals(htmlspecialchars('text', ENT_COMPAT, 'UTF-8'), $oTitle->getText());
|
$this->assertEquals('text', $oTitle->getText());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -41,7 +41,7 @@ class TitleTest extends \PHPUnit_Framework_TestCase
|
||||||
*/
|
*/
|
||||||
public function testStyleNull()
|
public function testStyleNull()
|
||||||
{
|
{
|
||||||
$oTitle = new Title(htmlspecialchars('text', ENT_COMPAT, 'UTF-8'));
|
$oTitle = new Title('text');
|
||||||
|
|
||||||
$this->assertNull($oTitle->getStyle());
|
$this->assertNull($oTitle->getStyle());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -126,6 +126,7 @@ class SettingsTest extends \PHPUnit_Framework_TestCase
|
||||||
'pdfRendererPath' => '',
|
'pdfRendererPath' => '',
|
||||||
'defaultFontName' => 'Arial',
|
'defaultFontName' => 'Arial',
|
||||||
'defaultFontSize' => 10,
|
'defaultFontSize' => 10,
|
||||||
|
'outputEscapingEnabled' => false,
|
||||||
);
|
);
|
||||||
|
|
||||||
// Test default value
|
// Test default value
|
||||||
|
|
|
||||||
|
|
@ -41,9 +41,9 @@ class FontTest extends \PHPUnit_Framework_TestCase
|
||||||
*/
|
*/
|
||||||
public function testInitiation()
|
public function testInitiation()
|
||||||
{
|
{
|
||||||
$object = new Font(htmlspecialchars('text', ENT_COMPAT, 'UTF-8'), array('alignment' => Jc::BOTH));
|
$object = new Font('text', array('alignment' => Jc::BOTH));
|
||||||
|
|
||||||
$this->assertEquals(htmlspecialchars('text', ENT_COMPAT, 'UTF-8'), $object->getStyleType());
|
$this->assertEquals('text', $object->getStyleType());
|
||||||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Paragraph', $object->getParagraphStyle());
|
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Paragraph', $object->getParagraphStyle());
|
||||||
$this->assertTrue(is_array($object->getStyleValues()));
|
$this->assertTrue(is_array($object->getStyleValues()));
|
||||||
}
|
}
|
||||||
|
|
@ -129,7 +129,7 @@ class FontTest extends \PHPUnit_Framework_TestCase
|
||||||
$section = $phpWord->addSection();
|
$section = $phpWord->addSection();
|
||||||
|
|
||||||
// Test style array
|
// Test style array
|
||||||
$text = $section->addText(htmlspecialchars('This is a test', ENT_COMPAT, 'UTF-8'), array('line-height' => 2.0));
|
$text = $section->addText('This is a test', array('line-height' => 2.0));
|
||||||
|
|
||||||
$doc = TestHelperDOCX::getDocument($phpWord);
|
$doc = TestHelperDOCX::getDocument($phpWord);
|
||||||
$element = $doc->getElement('/w:document/w:body/w:p/w:pPr/w:spacing');
|
$element = $doc->getElement('/w:document/w:body/w:p/w:pPr/w:spacing');
|
||||||
|
|
|
||||||
|
|
@ -124,7 +124,7 @@ class ParagraphTest extends \PHPUnit_Framework_TestCase
|
||||||
$section = $phpWord->addSection();
|
$section = $phpWord->addSection();
|
||||||
|
|
||||||
// Test style array
|
// Test style array
|
||||||
$text = $section->addText(htmlspecialchars('This is a test', ENT_COMPAT, 'UTF-8'), array(), array('line-height' => 2.0));
|
$text = $section->addText('This is a test', array(), array('line-height' => 2.0));
|
||||||
|
|
||||||
$doc = TestHelperDOCX::getDocument($phpWord);
|
$doc = TestHelperDOCX::getDocument($phpWord);
|
||||||
$element = $doc->getElement('/w:document/w:body/w:p/w:pPr/w:spacing');
|
$element = $doc->getElement('/w:document/w:body/w:p/w:pPr/w:spacing');
|
||||||
|
|
|
||||||
|
|
@ -116,7 +116,7 @@ final class TemplateProcessorTest extends \PHPUnit_Framework_TestCase
|
||||||
* We have to use error control below, because \XSLTProcessor::setParameter omits warning on failure.
|
* We have to use error control below, because \XSLTProcessor::setParameter omits warning on failure.
|
||||||
* This warning fails the test.
|
* This warning fails the test.
|
||||||
*/
|
*/
|
||||||
@$templateProcessor->applyXslStyleSheet($xslDOMDocument, array(1 => htmlspecialchars('somevalue', ENT_COMPAT, 'UTF-8')));
|
@$templateProcessor->applyXslStyleSheet($xslDOMDocument, array(1 => 'somevalue'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -157,9 +157,9 @@ final class TemplateProcessorTest extends \PHPUnit_Framework_TestCase
|
||||||
);
|
);
|
||||||
|
|
||||||
$docName = 'clone-test-result.docx';
|
$docName = 'clone-test-result.docx';
|
||||||
$templateProcessor->setValue('tableHeader', utf8_decode(htmlspecialchars('ééé', ENT_COMPAT, 'UTF-8')));
|
$templateProcessor->setValue('tableHeader', utf8_decode('ééé'));
|
||||||
$templateProcessor->cloneRow('userId', 1);
|
$templateProcessor->cloneRow('userId', 1);
|
||||||
$templateProcessor->setValue('userId#1', htmlspecialchars('Test', ENT_COMPAT, 'UTF-8'));
|
$templateProcessor->setValue('userId#1', 'Test');
|
||||||
$templateProcessor->saveAs($docName);
|
$templateProcessor->saveAs($docName);
|
||||||
$docFound = file_exists($docName);
|
$docFound = file_exists($docName);
|
||||||
unlink($docName);
|
unlink($docName);
|
||||||
|
|
@ -178,11 +178,7 @@ final class TemplateProcessorTest extends \PHPUnit_Framework_TestCase
|
||||||
$this->assertEquals(array('documentContent', 'headerValue', 'footerValue'), $templateProcessor->getVariables());
|
$this->assertEquals(array('documentContent', 'headerValue', 'footerValue'), $templateProcessor->getVariables());
|
||||||
|
|
||||||
$macroNames = array('headerValue', 'documentContent', 'footerValue');
|
$macroNames = array('headerValue', 'documentContent', 'footerValue');
|
||||||
$macroValues = array(
|
$macroValues = array('Header Value', 'Document text.', 'Footer Value');
|
||||||
htmlspecialchars('Header Value', ENT_COMPAT, 'UTF-8'),
|
|
||||||
htmlspecialchars('Document text.', ENT_COMPAT, 'UTF-8'),
|
|
||||||
htmlspecialchars('Footer Value', ENT_COMPAT, 'UTF-8')
|
|
||||||
);
|
|
||||||
$templateProcessor->setValue($macroNames, $macroValues);
|
$templateProcessor->setValue($macroNames, $macroValues);
|
||||||
|
|
||||||
$docName = 'header-footer-test-result.docx';
|
$docName = 'header-footer-test-result.docx';
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ class DomPDFTest extends \PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
$phpWord = new PhpWord();
|
$phpWord = new PhpWord();
|
||||||
$section = $phpWord->addSection();
|
$section = $phpWord->addSection();
|
||||||
$section->addText(htmlspecialchars('Test 1', ENT_COMPAT, 'UTF-8'));
|
$section->addText('Test 1');
|
||||||
|
|
||||||
$rendererName = Settings::PDF_RENDERER_DOMPDF;
|
$rendererName = Settings::PDF_RENDERER_DOMPDF;
|
||||||
$rendererLibraryPath = realpath(PHPWORD_TESTS_BASE_DIR . '/../vendor/dompdf/dompdf');
|
$rendererLibraryPath = realpath(PHPWORD_TESTS_BASE_DIR . '/../vendor/dompdf/dompdf');
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ class MPDFTest extends \PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
$phpWord = new PhpWord();
|
$phpWord = new PhpWord();
|
||||||
$section = $phpWord->addSection();
|
$section = $phpWord->addSection();
|
||||||
$section->addText(htmlspecialchars('Test 1', ENT_COMPAT, 'UTF-8'));
|
$section->addText('Test 1');
|
||||||
|
|
||||||
$rendererName = Settings::PDF_RENDERER_MPDF;
|
$rendererName = Settings::PDF_RENDERER_MPDF;
|
||||||
$rendererLibraryPath = realpath(PHPWORD_TESTS_BASE_DIR . '/../vendor/mpdf/mpdf');
|
$rendererLibraryPath = realpath(PHPWORD_TESTS_BASE_DIR . '/../vendor/mpdf/mpdf');
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ class TCPDFTest extends \PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
$phpWord = new PhpWord();
|
$phpWord = new PhpWord();
|
||||||
$section = $phpWord->addSection();
|
$section = $phpWord->addSection();
|
||||||
$section->addText(htmlspecialchars('Test 1', ENT_COMPAT, 'UTF-8'));
|
$section->addText('Test 1');
|
||||||
|
|
||||||
$rendererName = Settings::PDF_RENDERER_TCPDF;
|
$rendererName = Settings::PDF_RENDERER_TCPDF;
|
||||||
$rendererLibraryPath = realpath(PHPWORD_TESTS_BASE_DIR . '/../vendor/tecnickcom/tcpdf');
|
$rendererLibraryPath = realpath(PHPWORD_TESTS_BASE_DIR . '/../vendor/tecnickcom/tcpdf');
|
||||||
|
|
|
||||||
|
|
@ -202,9 +202,7 @@ class ElementTest extends \PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
$section->addFormField('textinput')->setName('MyTextBox');
|
$section->addFormField('textinput')->setName('MyTextBox');
|
||||||
$section->addFormField('checkbox')->setDefault(true)->setValue('Your name');
|
$section->addFormField('checkbox')->setDefault(true)->setValue('Your name');
|
||||||
$section->addFormField('dropdown')->setEntries(
|
$section->addFormField('dropdown')->setEntries(array('Choice 1', 'Choice 2', 'Choice 3'));
|
||||||
array(htmlspecialchars('Choice 1', ENT_COMPAT, 'UTF-8'), htmlspecialchars('Choice 2', ENT_COMPAT, 'UTF-8'), htmlspecialchars('Choice 3', ENT_COMPAT, 'UTF-8'))
|
|
||||||
);
|
|
||||||
|
|
||||||
$doc = TestHelperDOCX::getDocument($phpWord);
|
$doc = TestHelperDOCX::getDocument($phpWord);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -70,14 +70,14 @@ class DocumentTest extends \PHPUnit_Framework_TestCase
|
||||||
$section = $phpWord->addSection();
|
$section = $phpWord->addSection();
|
||||||
$section->addTOC();
|
$section->addTOC();
|
||||||
$section->addPageBreak();
|
$section->addPageBreak();
|
||||||
$section->addText(htmlspecialchars('After page break.', ENT_COMPAT, 'UTF-8'));
|
$section->addText('After page break.');
|
||||||
$section->addTitle(htmlspecialchars('Title 1', ENT_COMPAT, 'UTF-8'), 1);
|
$section->addTitle('Title 1', 1);
|
||||||
$section->addListItem(htmlspecialchars('List Item 1', ENT_COMPAT, 'UTF-8'), 0);
|
$section->addListItem('List Item 1', 0);
|
||||||
$section->addListItem(htmlspecialchars('List Item 2', ENT_COMPAT, 'UTF-8'), 0);
|
$section->addListItem('List Item 2', 0);
|
||||||
$section->addListItem(htmlspecialchars('List Item 3', ENT_COMPAT, 'UTF-8'), 0);
|
$section->addListItem('List Item 3', 0);
|
||||||
|
|
||||||
$section = $phpWord->addSection();
|
$section = $phpWord->addSection();
|
||||||
$section->addTitle(htmlspecialchars('Title 2', ENT_COMPAT, 'UTF-8'), 2);
|
$section->addTitle('Title 2', 2);
|
||||||
$section->addObject($objectSrc);
|
$section->addObject($objectSrc);
|
||||||
$section->addTextBox(array());
|
$section->addTextBox(array());
|
||||||
$section->addTextBox(
|
$section->addTextBox(
|
||||||
|
|
@ -92,7 +92,7 @@ class DocumentTest extends \PHPUnit_Framework_TestCase
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
$section->addTextBox(array('wrappingStyle' => 'tight', 'positioning' => 'absolute', 'alignment' => Jc::CENTER));
|
$section->addTextBox(array('wrappingStyle' => 'tight', 'positioning' => 'absolute', 'alignment' => Jc::CENTER));
|
||||||
$section->addListItemRun()->addText(htmlspecialchars('List item run 1', ENT_COMPAT, 'UTF-8'));
|
$section->addListItemRun()->addText('List item run 1');
|
||||||
$section->addField(
|
$section->addField(
|
||||||
'DATE',
|
'DATE',
|
||||||
array('dateformat' => 'dddd d MMMM yyyy H:mm:ss'),
|
array('dateformat' => 'dddd d MMMM yyyy H:mm:ss'),
|
||||||
|
|
@ -180,10 +180,10 @@ class DocumentTest extends \PHPUnit_Framework_TestCase
|
||||||
$fontStyle = new Font('text', array('alignment' => Jc::CENTER));
|
$fontStyle = new Font('text', array('alignment' => Jc::CENTER));
|
||||||
|
|
||||||
$section = $phpWord->addSection();
|
$section = $phpWord->addSection();
|
||||||
$section->addListItem(htmlspecialchars('List Item', ENT_COMPAT, 'UTF-8'), 0, null, null, 'pStyle'); // Style #5
|
$section->addListItem('List Item', 0, null, null, 'pStyle'); // Style #5
|
||||||
$section->addObject($objectSrc, array('alignment' => Jc::CENTER));
|
$section->addObject($objectSrc, array('alignment' => Jc::CENTER));
|
||||||
$section->addTOC($fontStyle);
|
$section->addTOC($fontStyle);
|
||||||
$section->addTitle(htmlspecialchars('Title 1', ENT_COMPAT, 'UTF-8'), 1);
|
$section->addTitle('Title 1', 1);
|
||||||
$section->addTOC('fStyle');
|
$section->addTOC('fStyle');
|
||||||
$table = $section->addTable('tStyle');
|
$table = $section->addTable('tStyle');
|
||||||
$table->setWidth(100);
|
$table->setWidth(100);
|
||||||
|
|
@ -216,7 +216,7 @@ class DocumentTest extends \PHPUnit_Framework_TestCase
|
||||||
$phpWord->addFontStyle($rStyle, array('bold' => true));
|
$phpWord->addFontStyle($rStyle, array('bold' => true));
|
||||||
$phpWord->addParagraphStyle($pStyle, array('hanging' => 120, 'indent' => 120));
|
$phpWord->addParagraphStyle($pStyle, array('hanging' => 120, 'indent' => 120));
|
||||||
$section = $phpWord->addSection();
|
$section = $phpWord->addSection();
|
||||||
$section->addText(htmlspecialchars('Test', ENT_COMPAT, 'UTF-8'), $rStyle, $pStyle);
|
$section->addText('Test', $rStyle, $pStyle);
|
||||||
$doc = TestHelperDOCX::getDocument($phpWord);
|
$doc = TestHelperDOCX::getDocument($phpWord);
|
||||||
|
|
||||||
$element = '/w:document/w:body/w:p/w:r/w:rPr/w:rStyle';
|
$element = '/w:document/w:body/w:p/w:r/w:rPr/w:rStyle';
|
||||||
|
|
@ -236,9 +236,9 @@ class DocumentTest extends \PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
$phpWord = new PhpWord();
|
$phpWord = new PhpWord();
|
||||||
$phpWord->addParagraphStyle($pStyle, $aStyle);
|
$phpWord->addParagraphStyle($pStyle, $aStyle);
|
||||||
$section = $phpWord->addSection(htmlspecialchars('Test', ENT_COMPAT, 'UTF-8'));
|
$section = $phpWord->addSection('Test');
|
||||||
$textrun = $section->addTextRun($pStyle);
|
$textrun = $section->addTextRun($pStyle);
|
||||||
$textrun->addText(htmlspecialchars('Test', ENT_COMPAT, 'UTF-8'));
|
$textrun->addText('Test');
|
||||||
$textrun->addTextBreak();
|
$textrun->addTextBreak();
|
||||||
$textrun = $section->addTextRun($aStyle);
|
$textrun = $section->addTextRun($aStyle);
|
||||||
$textrun->addLink('https://github.com/PHPOffice/PHPWord');
|
$textrun->addLink('https://github.com/PHPOffice/PHPWord');
|
||||||
|
|
@ -263,24 +263,14 @@ class DocumentTest extends \PHPUnit_Framework_TestCase
|
||||||
$paragraphStyleName = 'Paragraph Style';
|
$paragraphStyleName = 'Paragraph Style';
|
||||||
|
|
||||||
$expected = 'PHPWord on GitHub';
|
$expected = 'PHPWord on GitHub';
|
||||||
$section->addLink('https://github.com/PHPOffice/PHPWord', htmlspecialchars($expected, ENT_COMPAT, 'UTF-8'));
|
$section->addLink('https://github.com/PHPOffice/PHPWord', $expected);
|
||||||
$section->addLink(
|
$section->addLink('https://github.com/PHPOffice/PHPWord', 'Test', $fontStyleArray, $paragraphStyleArray);
|
||||||
'https://github.com/PHPOffice/PHPWord',
|
$section->addLink('https://github.com/PHPOffice/PHPWord', 'Test', $fontStyleName, $paragraphStyleName);
|
||||||
htmlspecialchars('Test', ENT_COMPAT, 'UTF-8'),
|
|
||||||
$fontStyleArray,
|
|
||||||
$paragraphStyleArray
|
|
||||||
);
|
|
||||||
$section->addLink(
|
|
||||||
'https://github.com/PHPOffice/PHPWord',
|
|
||||||
htmlspecialchars('Test', ENT_COMPAT, 'UTF-8'),
|
|
||||||
$fontStyleName,
|
|
||||||
$paragraphStyleName
|
|
||||||
);
|
|
||||||
|
|
||||||
$doc = TestHelperDOCX::getDocument($phpWord);
|
$doc = TestHelperDOCX::getDocument($phpWord);
|
||||||
$element = $doc->getElement('/w:document/w:body/w:p/w:hyperlink/w:r/w:t');
|
$element = $doc->getElement('/w:document/w:body/w:p/w:hyperlink/w:r/w:t');
|
||||||
|
|
||||||
$this->assertEquals(htmlspecialchars($expected, ENT_COMPAT, 'UTF-8'), $element->nodeValue);
|
$this->assertEquals($expected, $element->nodeValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -296,9 +286,9 @@ class DocumentTest extends \PHPUnit_Framework_TestCase
|
||||||
$paragraphStyleArray = array('alignment' => Jc::END);
|
$paragraphStyleArray = array('alignment' => Jc::END);
|
||||||
$paragraphStyleName = 'Paragraph';
|
$paragraphStyleName = 'Paragraph';
|
||||||
|
|
||||||
$footer->addPreserveText(htmlspecialchars('Page {PAGE}', ENT_COMPAT, 'UTF-8'));
|
$footer->addPreserveText('Page {PAGE}');
|
||||||
$footer->addPreserveText(htmlspecialchars('{PAGE}', ENT_COMPAT, 'UTF-8'), $fontStyleArray, $paragraphStyleArray);
|
$footer->addPreserveText('{PAGE}', $fontStyleArray, $paragraphStyleArray);
|
||||||
$footer->addPreserveText(htmlspecialchars('{PAGE}', ENT_COMPAT, 'UTF-8'), $fontStyleName, $paragraphStyleName);
|
$footer->addPreserveText('{PAGE}', $fontStyleName, $paragraphStyleName);
|
||||||
|
|
||||||
$doc = TestHelperDOCX::getDocument($phpWord);
|
$doc = TestHelperDOCX::getDocument($phpWord);
|
||||||
$preserve = $doc->getElement('w:p/w:r[2]/w:instrText', 'word/footer1.xml');
|
$preserve = $doc->getElement('w:p/w:r[2]/w:instrText', 'word/footer1.xml');
|
||||||
|
|
@ -387,7 +377,7 @@ class DocumentTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
$phpWord = new PhpWord();
|
$phpWord = new PhpWord();
|
||||||
$phpWord->addTitleStyle(1, array('bold' => true), array('spaceAfter' => 240));
|
$phpWord->addTitleStyle(1, array('bold' => true), array('spaceAfter' => 240));
|
||||||
$phpWord->addSection()->addTitle(htmlspecialchars('Test', ENT_COMPAT, 'UTF-8'), 1);
|
$phpWord->addSection()->addTitle('Test', 1);
|
||||||
$doc = TestHelperDOCX::getDocument($phpWord);
|
$doc = TestHelperDOCX::getDocument($phpWord);
|
||||||
|
|
||||||
$element = '/w:document/w:body/w:p/w:pPr/w:pStyle';
|
$element = '/w:document/w:body/w:p/w:pPr/w:pStyle';
|
||||||
|
|
@ -406,11 +396,11 @@ class DocumentTest extends \PHPUnit_Framework_TestCase
|
||||||
// $phpWord->addFontStyle($rStyle, array('bold' => true));
|
// $phpWord->addFontStyle($rStyle, array('bold' => true));
|
||||||
// $phpWord->addParagraphStyle($pStyle, array('hanging' => 120, 'indent' => 120));
|
// $phpWord->addParagraphStyle($pStyle, array('hanging' => 120, 'indent' => 120));
|
||||||
$section = $phpWord->addSection();
|
$section = $phpWord->addSection();
|
||||||
$section->addCheckBox(htmlspecialchars('Check1', ENT_COMPAT, 'UTF-8'), htmlspecialchars('Test', ENT_COMPAT, 'UTF-8'), $rStyle, $pStyle);
|
$section->addCheckBox('Check1', 'Test', $rStyle, $pStyle);
|
||||||
$doc = TestHelperDOCX::getDocument($phpWord);
|
$doc = TestHelperDOCX::getDocument($phpWord);
|
||||||
|
|
||||||
$element = '/w:document/w:body/w:p/w:r/w:fldChar/w:ffData/w:name';
|
$element = '/w:document/w:body/w:p/w:r/w:fldChar/w:ffData/w:name';
|
||||||
$this->assertEquals(htmlspecialchars('Check1', ENT_COMPAT, 'UTF-8'), $doc->getElementAttribute($element, 'w:val'));
|
$this->assertEquals('Check1', $doc->getElementAttribute($element, 'w:val'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -429,7 +419,7 @@ class DocumentTest extends \PHPUnit_Framework_TestCase
|
||||||
'pageBreakBefore' => true,
|
'pageBreakBefore' => true,
|
||||||
);
|
);
|
||||||
foreach ($attributes as $attribute => $value) {
|
foreach ($attributes as $attribute => $value) {
|
||||||
$section->addText(htmlspecialchars('Test', ENT_COMPAT, 'UTF-8'), null, array($attribute => $value));
|
$section->addText('Test', null, array($attribute => $value));
|
||||||
}
|
}
|
||||||
$doc = TestHelperDOCX::getDocument($phpWord);
|
$doc = TestHelperDOCX::getDocument($phpWord);
|
||||||
|
|
||||||
|
|
@ -467,7 +457,7 @@ class DocumentTest extends \PHPUnit_Framework_TestCase
|
||||||
$styles['smallCaps'] = true;
|
$styles['smallCaps'] = true;
|
||||||
|
|
||||||
$section = $phpWord->addSection();
|
$section = $phpWord->addSection();
|
||||||
$section->addText(htmlspecialchars('Test', ENT_COMPAT, 'UTF-8'), $styles);
|
$section->addText('Test', $styles);
|
||||||
$doc = TestHelperDOCX::getDocument($phpWord);
|
$doc = TestHelperDOCX::getDocument($phpWord);
|
||||||
|
|
||||||
$parent = '/w:document/w:body/w:p/w:r/w:rPr';
|
$parent = '/w:document/w:body/w:p/w:r/w:rPr';
|
||||||
|
|
@ -519,14 +509,14 @@ class DocumentTest extends \PHPUnit_Framework_TestCase
|
||||||
$table->setWidth = 100;
|
$table->setWidth = 100;
|
||||||
$table->addRow($rHeight, $rStyles);
|
$table->addRow($rHeight, $rStyles);
|
||||||
$cell = $table->addCell($cWidth, $cStyles);
|
$cell = $table->addCell($cWidth, $cStyles);
|
||||||
$cell->addText(htmlspecialchars('Test', ENT_COMPAT, 'UTF-8'));
|
$cell->addText('Test');
|
||||||
$cell->addTextBreak();
|
$cell->addTextBreak();
|
||||||
$cell->addLink('https://github.com/PHPOffice/PHPWord');
|
$cell->addLink('https://github.com/PHPOffice/PHPWord');
|
||||||
$cell->addListItem(htmlspecialchars('Test', ENT_COMPAT, 'UTF-8'));
|
$cell->addListItem('Test');
|
||||||
$cell->addImage($imageSrc);
|
$cell->addImage($imageSrc);
|
||||||
$cell->addObject($objectSrc);
|
$cell->addObject($objectSrc);
|
||||||
$textrun = $cell->addTextRun();
|
$textrun = $cell->addTextRun();
|
||||||
$textrun->addText(htmlspecialchars('Test', ENT_COMPAT, 'UTF-8'));
|
$textrun->addText('Test');
|
||||||
|
|
||||||
$doc = TestHelperDOCX::getDocument($phpWord);
|
$doc = TestHelperDOCX::getDocument($phpWord);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -33,11 +33,11 @@ class FooterTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
$imageSrc = __DIR__ . '/../../../_files/images/PhpWord.png';
|
$imageSrc = __DIR__ . '/../../../_files/images/PhpWord.png';
|
||||||
$container = new \PhpOffice\PhpWord\Element\Footer(1);
|
$container = new \PhpOffice\PhpWord\Element\Footer(1);
|
||||||
$container->addText(htmlspecialchars('', ENT_COMPAT, 'UTF-8'));
|
$container->addText('');
|
||||||
$container->addPreserveText(htmlspecialchars('', ENT_COMPAT, 'UTF-8'));
|
$container->addPreserveText('');
|
||||||
$container->addTextBreak();
|
$container->addTextBreak();
|
||||||
$container->addTextRun();
|
$container->addTextRun();
|
||||||
$container->addTable()->addRow()->addCell()->addText(htmlspecialchars('', ENT_COMPAT, 'UTF-8'));
|
$container->addTable()->addRow()->addCell()->addText('');
|
||||||
$container->addImage($imageSrc);
|
$container->addImage($imageSrc);
|
||||||
|
|
||||||
$writer = new Word2007();
|
$writer = new Word2007();
|
||||||
|
|
|
||||||
|
|
@ -36,13 +36,13 @@ class FootnotesTest extends \PHPUnit_Framework_TestCase
|
||||||
$phpWord = new PhpWord();
|
$phpWord = new PhpWord();
|
||||||
$phpWord->addParagraphStyle('pStyle', array('alignment' => Jc::START));
|
$phpWord->addParagraphStyle('pStyle', array('alignment' => Jc::START));
|
||||||
$section = $phpWord->addSection();
|
$section = $phpWord->addSection();
|
||||||
$section->addText(htmlspecialchars('Text', ENT_COMPAT, 'UTF-8'));
|
$section->addText('Text');
|
||||||
$footnote1 = $section->addFootnote('pStyle');
|
$footnote1 = $section->addFootnote('pStyle');
|
||||||
$footnote1->addText(htmlspecialchars('Footnote', ENT_COMPAT, 'UTF-8'));
|
$footnote1->addText('Footnote');
|
||||||
$footnote1->addTextBreak();
|
$footnote1->addTextBreak();
|
||||||
$footnote1->addLink('https://github.com/PHPOffice/PHPWord');
|
$footnote1->addLink('https://github.com/PHPOffice/PHPWord');
|
||||||
$footnote2 = $section->addEndnote(array('alignment' => Jc::START));
|
$footnote2 = $section->addEndnote(array('alignment' => Jc::START));
|
||||||
$footnote2->addText(htmlspecialchars('Endnote', ENT_COMPAT, 'UTF-8'));
|
$footnote2->addText('Endnote');
|
||||||
$doc = TestHelperDOCX::getDocument($phpWord);
|
$doc = TestHelperDOCX::getDocument($phpWord);
|
||||||
|
|
||||||
$this->assertTrue($doc->elementExists('/w:document/w:body/w:p/w:r/w:footnoteReference'));
|
$this->assertTrue($doc->elementExists('/w:document/w:body/w:p/w:r/w:footnoteReference'));
|
||||||
|
|
|
||||||
|
|
@ -33,11 +33,11 @@ class HeaderTest extends \PHPUnit_Framework_TestCase
|
||||||
$imageSrc = __DIR__ . '/../../../_files/images/PhpWord.png';
|
$imageSrc = __DIR__ . '/../../../_files/images/PhpWord.png';
|
||||||
|
|
||||||
$container = new \PhpOffice\PhpWord\Element\Header(1);
|
$container = new \PhpOffice\PhpWord\Element\Header(1);
|
||||||
$container->addText(htmlspecialchars('Test', ENT_COMPAT, 'UTF-8'));
|
$container->addText('Test');
|
||||||
$container->addPreserveText(htmlspecialchars('', ENT_COMPAT, 'UTF-8'));
|
$container->addPreserveText('');
|
||||||
$container->addTextBreak();
|
$container->addTextBreak();
|
||||||
$container->addTextRun();
|
$container->addTextRun();
|
||||||
$container->addTable()->addRow()->addCell()->addText(htmlspecialchars('', ENT_COMPAT, 'UTF-8'));
|
$container->addTable()->addRow()->addCell()->addText('');
|
||||||
$container->addImage($imageSrc);
|
$container->addImage($imageSrc);
|
||||||
$container->addWatermark($imageSrc);
|
$container->addWatermark($imageSrc);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,7 @@ class FontTest extends \PHPUnit_Framework_TestCase
|
||||||
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||||
$section = $phpWord->addSection();
|
$section = $phpWord->addSection();
|
||||||
$textrun = $section->addTextRun();
|
$textrun = $section->addTextRun();
|
||||||
$textrun->addText(htmlspecialchars('سلام این یک پاراگراف راست به چپ است', ENT_COMPAT, 'UTF-8'), array('rtl' => true));
|
$textrun->addText('سلام این یک پاراگراف راست به چپ است', array('rtl' => true));
|
||||||
$doc = TestHelperDOCX::getDocument($phpWord, 'Word2007');
|
$doc = TestHelperDOCX::getDocument($phpWord, 'Word2007');
|
||||||
|
|
||||||
$file = 'word/document.xml';
|
$file = 'word/document.xml';
|
||||||
|
|
|
||||||
|
|
@ -79,12 +79,12 @@ class Word2007Test extends \PHPUnit_Framework_TestCase
|
||||||
$phpWord->addFontStyle('Font', array('size' => 11));
|
$phpWord->addFontStyle('Font', array('size' => 11));
|
||||||
$phpWord->addParagraphStyle('Paragraph', array('alignment' => Jc::CENTER));
|
$phpWord->addParagraphStyle('Paragraph', array('alignment' => Jc::CENTER));
|
||||||
$section = $phpWord->addSection();
|
$section = $phpWord->addSection();
|
||||||
$section->addText(htmlspecialchars('Test 1', ENT_COMPAT, 'UTF-8'), 'Font', 'Paragraph');
|
$section->addText('Test 1', 'Font', 'Paragraph');
|
||||||
$section->addTextBreak();
|
$section->addTextBreak();
|
||||||
$section->addText(htmlspecialchars('Test 2', ENT_COMPAT, 'UTF-8'));
|
$section->addText('Test 2');
|
||||||
$section = $phpWord->addSection();
|
$section = $phpWord->addSection();
|
||||||
$textrun = $section->addTextRun();
|
$textrun = $section->addTextRun();
|
||||||
$textrun->addText(htmlspecialchars('Test 3', ENT_COMPAT, 'UTF-8'));
|
$textrun->addText('Test 3');
|
||||||
$footnote = $textrun->addFootnote();
|
$footnote = $textrun->addFootnote();
|
||||||
$footnote->addLink('https://github.com/PHPOffice/PHPWord');
|
$footnote->addLink('https://github.com/PHPOffice/PHPWord');
|
||||||
$header = $section->addHeader();
|
$header = $section->addHeader();
|
||||||
|
|
@ -108,9 +108,9 @@ class Word2007Test extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
$phpWord = new PhpWord();
|
$phpWord = new PhpWord();
|
||||||
$section = $phpWord->addSection();
|
$section = $phpWord->addSection();
|
||||||
$section->addText(htmlspecialchars('Test', ENT_COMPAT, 'UTF-8'));
|
$section->addText('Test');
|
||||||
$footnote = $section->addFootnote();
|
$footnote = $section->addFootnote();
|
||||||
$footnote->addText(htmlspecialchars('Test', ENT_COMPAT, 'UTF-8'));
|
$footnote->addText('Test');
|
||||||
|
|
||||||
$writer = new Word2007($phpWord);
|
$writer = new Word2007($phpWord);
|
||||||
$writer->setUseDiskCaching(true);
|
$writer->setUseDiskCaching(true);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue