Skip to content

Commit 71b60e9

Browse files
committed
Merge branch 'develop' into PHPOffice#140-bskrtich-pclzip
2 parents 86274aa + 2d72446 commit 71b60e9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+2768
-1785
lines changed

CHANGELOG.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,22 @@ This is the changelog between releases of PHPWord. Releases are listed in revers
77
### Features
88

99
- Image: Get image dimensions without EXIF extension - @andrew-kzoo GH-184
10-
- Table: Add tblGrid element for Libre/Open Office table sizing - @gianis6 GH-183
10+
- Table: Add `tblGrid` element for Libre/Open Office table sizing - @gianis6 GH-183
11+
- Footnote: Ability to insert textbreak in footnote `$footnote->addTextBreak()` - @ivanlanin
12+
- Footnote: Ability to style footnote reference mark by using `FootnoteReference` style - @ivanlanin
13+
- Font: Add `bgColor` to font style to define background using HEX color - @jcarignan GH-168
14+
- Table: Add `exactHeight` to row style to define whether row height should be exact or atLeast - @jcarignan GH-168
15+
- Element: New `CheckBox` element for sections and table cells - @ozilion GH-156
1116

1217
### Bugfixes
1318

14-
-
19+
- Footnote: Footnote content doesn't show footnote reference number - @ivanlanin GH-170
1520

1621
### Miscellaneous
1722

1823
- Documentation: Simplify page level docblock - @ivanlanin GH-179
24+
- Writer: Refactor writer classes and make a new Writer abstract class - @ivanlanin GH-160
25+
- Reader: Rename AbstractReader > Reader - @ivanlanin
1926

2027
## 0.9.1 - 27 Mar 2014
2128

composer.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525
{
2626
"name": "Ivan Lanin",
2727
"homepage": "http://ivan.lanin.org"
28+
},
29+
{
30+
"name": "Roman Syroeshko",
31+
"homepage": "http://ru.linkedin.com/pub/roman-syroeshko/34/a53/994/"
2832
}
2933
],
3034
"require": {

docs/elements.rst

Lines changed: 42 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ Available font styles:
6767
- ``strikethrough`` Strikethrough, *true* or *false*
6868
- ``color`` Font color, e.g. *FF0000*
6969
- ``fgColor`` Font highlight color, e.g. *yellow*, *green*, *blue*
70+
- ``bgColor`` Font background color, e.g. *FF0000*
7071

7172
Paragraph style
7273
^^^^^^^^^^^^^^^
@@ -201,27 +202,28 @@ Table, row, and cell styles
201202

202203
Table styles:
203204

204-
- ``$width`` Table width in percent
205-
- ``$bgColor`` Background color, e.g. '9966CC'
206-
- ``$border(Top|Right|Bottom|Left)Size`` Border size in twips
207-
- ``$border(Top|Right|Bottom|Left)Color`` Border color, e.g. '9966CC'
208-
- ``$cellMargin(Top|Right|Bottom|Left)`` Cell margin in twips
205+
- ``width`` Table width in percent
206+
- ``bgColor`` Background color, e.g. '9966CC'
207+
- ``border(Top|Right|Bottom|Left)Size`` Border size in twips
208+
- ``border(Top|Right|Bottom|Left)Color`` Border color, e.g. '9966CC'
209+
- ``cellMargin(Top|Right|Bottom|Left)`` Cell margin in twips
209210

210211
Row styles:
211212

212213
- ``tblHeader`` Repeat table row on every new page, *true* or *false*
213214
- ``cantSplit`` Table row cannot break across pages, *true* or *false*
215+
- ``exactHeight`` Row height is exact or at least
214216

215217
Cell styles:
216218

217-
- ``$width`` Cell width in twips
218-
- ``$valign`` Vertical alignment, *top*, *center*, *both*, *bottom*
219-
- ``$textDirection`` Direction of text
220-
- ``$bgColor`` Background color, e.g. '9966CC'
221-
- ``$border(Top|Right|Bottom|Left)Size`` Border size in twips
222-
- ``$border(Top|Right|Bottom|Left)Color`` Border color, e.g. '9966CC'
223-
- ``$gridSpan`` Number of columns spanned
224-
- ``$vMerge`` *restart* or *continue*
219+
- ``width`` Cell width in twips
220+
- ``valign`` Vertical alignment, *top*, *center*, *both*, *bottom*
221+
- ``textDirection`` Direction of text
222+
- ``bgColor`` Background color, e.g. '9966CC'
223+
- ``border(Top|Right|Bottom|Left)Size`` Border size in twips
224+
- ``border(Top|Right|Bottom|Left)Color`` Border color, e.g. '9966CC'
225+
- ``gridSpan`` Number of columns spanned
226+
- ``vMerge`` *restart* or *continue*
225227

226228
Cell span
227229
~~~~~~~~~
@@ -326,7 +328,8 @@ Footnotes
326328
---------
327329

328330
You can create footnotes in texts or textruns, but it's recommended to
329-
use textrun to have better layout.
331+
use textrun to have better layout. You can use ``addText``, ``addLink``,
332+
and ``addTextBreak`` on a footnote.
330333

331334
On textrun:
332335

@@ -335,7 +338,11 @@ On textrun:
335338
$textrun = $section->createTextRun();
336339
$textrun->addText('Lead text.');
337340
$footnote = $textrun->createFootnote();
338-
$footnote->addText('Footnote text.');
341+
$footnote->addText('Footnote text can have ');
342+
$footnote->addLink('http://test.com', 'links');
343+
$footnote->addText('.');
344+
$footnote->addTextBreak();
345+
$footnote->addText('And text break.');
339346
$textrun->addText('Trailing text.');
340347
341348
On text:
@@ -345,3 +352,23 @@ On text:
345352
$section->addText('Lead text.');
346353
$footnote = $section->createFootnote();
347354
$footnote->addText('Footnote text.');
355+
356+
The footnote reference number will be displayed with decimal number starting
357+
from 1. This number use ``FooterReference`` style which you can redefine by
358+
``addFontStyle`` method. Default value for this style is
359+
``array('superScript' => true)``;
360+
361+
Checkboxes
362+
----------
363+
364+
Checkbox elements can be added to sections or table cells by using
365+
``addCheckBox``.
366+
367+
.. code-block:: php
368+
369+
$section->addCheckBox($name, $text, [$fontStyle], [$paragraphStyle])
370+
371+
- ``$name`` Name of the check box.
372+
- ``$text`` Text following the check box
373+
- ``$fontStyle`` See "Font style" section.
374+
- ``$paragraphStyle`` See "Paragraph style" section.

samples/Sample_06_Footnote.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
$footnote->addText(' All elements are placed inside a paragraph.', 'ColoredText');
2525
$footnote->addText(' The best search engine: ');
2626
$footnote->addLink('http://www.google.com', null, 'NLink');
27-
$footnote->addText('. Also not bad: ');
27+
$footnote->addText('. Also not bad:');
28+
$footnote->addTextBreak();
2829
$footnote->addLink('http://www.bing.com', null, 'NLink');
2930

3031
$textrun->addText('The trailing text in the paragraph.');

samples/Sample_13_Images.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
$source = 'http://php.net/images/logos/php-med-trans-light.gif';
1919
$section->addText("Remote image from: {$source}");
20-
$section->addMemoryImage($source);
20+
$section->addImage($source);
2121
// End code
2222

2323
// Save file

samples/Sample_20_BGColor.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
include_once 'Sample_Header.php';
3+
4+
// New Word document
5+
echo date('H:i:s'), " Create new PhpWord object", \EOL;
6+
$phpWord = new \PhpOffice\PhpWord\PhpWord();
7+
$section = $phpWord->createSection();
8+
9+
$section->addText("This is some text highlighted using fgColor (limited to 15 colors) ", array("fgColor" => \PhpOffice\PhpWord\Style\Font::FGCOLOR_YELLOW));
10+
$section->addText("This one uses bgColor and is using hex value (0xfbbb10)", array("bgColor" => "fbbb10"));
11+
$section->addText("Compatible with font colors", array("color"=>"0000ff", "bgColor" => "fbbb10"));
12+
13+
// Save file
14+
$name = basename(__FILE__, '.php');
15+
$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf');
16+
foreach ($writers as $writer => $extension) {
17+
echo date('H:i:s'), " Write to {$writer} format", \EOL;
18+
$xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, $writer);
19+
$xmlWriter->save("{$name}.{$extension}");
20+
rename("{$name}.{$extension}", "results/{$name}.{$extension}");
21+
}
22+
23+
include_once 'Sample_Footer.php';

samples/Sample_21_TableRowRules.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
include_once 'Sample_Header.php';
3+
4+
// New Word document
5+
echo date('H:i:s'), " Create new PhpWord object", \EOL;
6+
$phpWord = new \PhpOffice\PhpWord\PhpWord();
7+
$section = $phpWord->createSection();
8+
9+
$section->addText("By default, when you insert an image, it adds a textbreak after its content.");
10+
$section->addText("If we want a simple border around an image, we wrap the image inside a table->row->cell");
11+
$section->addText("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:");
12+
13+
$table1 = $section->addTable(array("cellMargin" => 0, "cellMarginRight" => 0, "cellMarginBottom" => 0, "cellMarginLeft" => 0));
14+
$table1->addRow(3750);
15+
$cell1 = $table1->addCell(null, array("valign" => "top", "borderSize" => 30, "borderColor" => "ff0000"));
16+
$cell1->addImage("./resources/_earth.jpg", array("width" => 250, "height" => 250, "align" => "center"));
17+
18+
$section->addTextBreak();
19+
$section->addText("But if we set the rowStyle 'exactHeight' to true, the real row height is used, removing the textbreak:");
20+
21+
$table2 = $section->addTable(array("cellMargin" => 0, "cellMarginRight" => 0, "cellMarginBottom" => 0, "cellMarginLeft" => 0));
22+
$table2->addRow(3750, array("exactHeight" => true));
23+
$cell2 = $table2->addCell(null, array("valign" => "top", "borderSize" => 30, "borderColor" => "00ff00"));
24+
$cell2->addImage("./resources/_earth.jpg", array("width" => 250, "height" => 250, "align" => "center"));
25+
26+
$section->addTextBreak();
27+
$section->addText("In this example, image is 250px height. Rows are calculated in twips, and 1px = 15twips.");
28+
$section->addText("So: $"."table2->addRow(3750, array('exactHeight'=>true));");
29+
30+
// Save file
31+
$name = basename(__FILE__, '.php');
32+
$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf');
33+
foreach ($writers as $writer => $extension) {
34+
echo date('H:i:s'), " Write to {$writer} format", \EOL;
35+
$xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, $writer);
36+
$xmlWriter->save("{$name}.{$extension}");
37+
rename("{$name}.{$extension}", "results/{$name}.{$extension}");
38+
}
39+
40+
include_once 'Sample_Footer.php';

samples/Sample_22_CheckBox.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
include_once 'Sample_Header.php';
3+
4+
// New Word document
5+
echo date('H:i:s'), " Create new PhpWord object", \EOL;
6+
$phpWord = new \PhpOffice\PhpWord\PhpWord();
7+
8+
$section = $phpWord->createSection();
9+
$section->addText('Check box in section');
10+
$section->addCheckBox('chkBox1', 'Checkbox 1');
11+
$section->addText('Check box in table cell');
12+
$table = $section->addTable();
13+
$table->addRow();
14+
$cell = $table->addCell();
15+
$cell->addCheckBox('chkBox2', 'Checkbox 2');
16+
17+
// Save file
18+
$name = basename(__FILE__, '.php');
19+
$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf');
20+
foreach ($writers as $writer => $extension) {
21+
echo date('H:i:s'), " Write to {$writer} format", \EOL;
22+
$xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, $writer);
23+
$xmlWriter->save("{$name}.{$extension}");
24+
rename("{$name}.{$extension}", "results/{$name}.{$extension}");
25+
}
26+
27+
include_once 'Sample_Footer.php';

samples/Sample_Footer.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,20 @@
33
* Footer file
44
*/
55
// Do not show execution time for index
6-
if (!$isIndexFile) {
6+
if (!IS_INDEX) {
77
echo date('H:i:s'), " Done writing file(s)", EOL;
88
echo date('H:i:s'), " Peak memory usage: ", (memory_get_peak_usage(true) / 1024 / 1024), " MB", EOL;
99
}
1010
// Show message when executed with CLI, show links when using browsers
1111
if (CLI) {
1212
echo 'The results are stored in the "results" subdirectory.', EOL;
1313
} else {
14-
if (!$isIndexFile) {
14+
if (!IS_INDEX) {
1515
$types = array('docx', 'odt', 'rtf');
1616
echo '<p>&nbsp;</p>';
1717
echo '<p>Results: ';
1818
foreach ($types as $type) {
19-
$result = "results/{$sampleFile}.{$type}";
19+
$result = 'results/' . SCRIPT_FILENAME . '.' . $type;
2020
if (file_exists($result)) {
2121
echo "<a href='{$result}' class='btn btn-primary'>{$type}</a> ";
2222
}

samples/Sample_Header.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
error_reporting(E_ALL);
66
define('CLI', (PHP_SAPI == 'cli') ? true : false);
77
define('EOL', CLI ? PHP_EOL : '<br />');
8+
define('SCRIPT_FILENAME', basename($_SERVER['SCRIPT_FILENAME'], '.php'));
9+
define('IS_INDEX', SCRIPT_FILENAME == 'index');
810

911
require_once '../src/PhpWord/Autoloader.php';
1012
PhpOffice\PhpWord\Autoloader::register();
@@ -15,12 +17,10 @@
1517
}
1618

1719
// Set titles and names
18-
$sampleFile = basename($_SERVER['SCRIPT_FILENAME'], '.php');
19-
$isIndexFile = ($sampleFile == 'index');
20-
$pageHeading = str_replace('_', ' ', $sampleFile);
21-
$pageTitle = $isIndexFile ? 'Welcome to ' : "{$pageHeading} - ";
20+
$pageHeading = str_replace('_', ' ', SCRIPT_FILENAME);
21+
$pageTitle = IS_INDEX ? 'Welcome to ' : "{$pageHeading} - ";
2222
$pageTitle .= 'PHPWord';
23-
$pageHeading = $isIndexFile ? '' : "<h1>{$pageHeading}</h1>";
23+
$pageHeading = IS_INDEX ? '' : "<h1>{$pageHeading}</h1>";
2424
// Populate samples
2525
$files = '';
2626
if ($handle = opendir('.')) {

0 commit comments

Comments
 (0)