Skip to content

Commit d54d47d

Browse files
committed
Merge pull request #203 from ivanlanin/html
Basic HTML Writer
2 parents e78489b + 5a01927 commit d54d47d

29 files changed

+827
-228
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ This is the changelog between releases of PHPWord. Releases are listed in revers
44

55
## 0.10.0 - Not yet released
66

7-
This release marked heavy refactorings on internal code structure with the creation of some abstract classes to reduce code duplication. `Element` subnamespace is introduced in this release to replace `Section`. Word2007 reader capability is greatly enhanced. Endnote is introduced. List numbering is now customizable.
7+
This release marked heavy refactorings on internal code structure with the creation of some abstract classes to reduce code duplication. `Element` subnamespace is introduced in this release to replace `Section`. Word2007 reader capability is greatly enhanced. Endnote is introduced. List numbering is now customizable. Basic HTML support is enabled.
88

99
### Features
1010

@@ -32,6 +32,7 @@ This release marked heavy refactorings on internal code structure with the creat
3232
- ListItem: Ability to create custom list and reset list number - @ivanlanin GH-10 GH-198
3333
- ODT Writer: Basic table writing support - @ivanlanin
3434
- Image: Keep image aspect ratio if only 1 dimension styled - @japonicus GH-194
35+
- HTML Writer: Basic HTML writer initiated - @ivanlanin GH-203 GH-67 GH-147
3536

3637
### Bugfixes
3738

samples/Sample_01_SimpleText.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,7 @@
4545
$section->addImage('resources/_earth.jpg', array('width'=>18, 'height'=>18));
4646

4747
// Save file
48-
$name = basename(__FILE__, '.php');
49-
$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf');
50-
foreach ($writers as $writer => $extension) {
51-
echo date('H:i:s'), " Write to {$writer} format", EOL;
52-
$xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, $writer);
53-
$xmlWriter->save("{$name}.{$extension}");
54-
rename("{$name}.{$extension}", "results/{$name}.{$extension}");
48+
echo write($phpWord, basename(__FILE__, '.php'), $writers);
49+
if (!CLI) {
50+
include_once 'Sample_Footer.php';
5551
}
56-
57-
include_once 'Sample_Footer.php';

samples/Sample_02_TabStops.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,7 @@
3333
$section->addText("\tCenter Aligned", null, 'centerTab');
3434

3535
// Save file
36-
$name = basename(__FILE__, '.php');
37-
$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf');
38-
foreach ($writers as $writer => $extension) {
39-
echo date('H:i:s'), " Write to {$writer} format", EOL;
40-
$xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, $writer);
41-
$xmlWriter->save("{$name}.{$extension}");
42-
rename("{$name}.{$extension}", "results/{$name}.{$extension}");
36+
echo write($phpWord, basename(__FILE__, '.php'), $writers);
37+
if (!CLI) {
38+
include_once 'Sample_Footer.php';
4339
}
44-
45-
include_once 'Sample_Footer.php';

samples/Sample_03_Sections.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,7 @@
2626
$section->addFooter()->addText('Footer');
2727

2828
// Save file
29-
$name = basename(__FILE__, '.php');
30-
$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf');
31-
foreach ($writers as $writer => $extension) {
32-
echo date('H:i:s'), " Write to {$writer} format", EOL;
33-
$xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, $writer);
34-
$xmlWriter->save("{$name}.{$extension}");
35-
rename("{$name}.{$extension}", "results/{$name}.{$extension}");
29+
echo write($phpWord, basename(__FILE__, '.php'), $writers);
30+
if (!CLI) {
31+
include_once 'Sample_Footer.php';
3632
}
37-
38-
include_once 'Sample_Footer.php';

samples/Sample_04_Textrun.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,7 @@
3434
$textrun->addText(' Here is some more text. ');
3535

3636
// Save file
37-
$name = basename(__FILE__, '.php');
38-
$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf');
39-
foreach ($writers as $writer => $extension) {
40-
echo date('H:i:s'), " Write to {$writer} format", EOL;
41-
$xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, $writer);
42-
$xmlWriter->save("{$name}.{$extension}");
43-
rename("{$name}.{$extension}", "results/{$name}.{$extension}");
37+
echo write($phpWord, basename(__FILE__, '.php'), $writers);
38+
if (!CLI) {
39+
include_once 'Sample_Footer.php';
4440
}
45-
46-
include_once 'Sample_Footer.php';

samples/Sample_05_Multicolumn.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,7 @@
3636
$section->addText('Normal paragraph again.');
3737

3838
// Save file
39-
$name = basename(__FILE__, '.php');
40-
$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf');
41-
foreach ($writers as $writer => $extension) {
42-
echo date('H:i:s'), " Write to {$writer} format", EOL;
43-
$xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, $writer);
44-
$xmlWriter->save("{$name}.{$extension}");
45-
rename("{$name}.{$extension}", "results/{$name}.{$extension}");
39+
echo write($phpWord, basename(__FILE__, '.php'), $writers);
40+
if (!CLI) {
41+
include_once 'Sample_Footer.php';
4642
}
47-
48-
include_once 'Sample_Footer.php';

samples/Sample_06_Footnote.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,7 @@
3838
$footnote->addText('The reference for this is wrapped in its own line');
3939

4040
// Save file
41-
$name = basename(__FILE__, '.php');
42-
$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf');
43-
foreach ($writers as $writer => $extension) {
44-
echo date('H:i:s'), " Write to {$writer} format", EOL;
45-
$xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, $writer);
46-
$xmlWriter->save("{$name}.{$extension}");
47-
rename("{$name}.{$extension}", "results/{$name}.{$extension}");
41+
echo write($phpWord, basename(__FILE__, '.php'), $writers);
42+
if (!CLI) {
43+
include_once 'Sample_Footer.php';
4844
}
49-
50-
include_once 'Sample_Footer.php';

samples/Sample_08_ParagraphPagination.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,7 @@
4646
null, array('pageBreakBefore' => true));
4747

4848
// Save file
49-
$name = basename(__FILE__, '.php');
50-
$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf');
51-
foreach ($writers as $writer => $extension) {
52-
echo date('H:i:s'), " Write to {$writer} format", EOL;
53-
$xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, $writer);
54-
$xmlWriter->save("{$name}.{$extension}");
55-
rename("{$name}.{$extension}", "results/{$name}.{$extension}");
49+
echo write($phpWord, basename(__FILE__, '.php'), $writers);
50+
if (!CLI) {
51+
include_once 'Sample_Footer.php';
5652
}
57-
58-
include_once 'Sample_Footer.php';

samples/Sample_09_Tables.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,7 @@
8585
$table->addCell(null, $cellRowContinue);
8686

8787
// Save file
88-
$name = basename(__FILE__, '.php');
89-
$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf');
90-
foreach ($writers as $writer => $extension) {
91-
echo date('H:i:s'), " Write to {$writer} format", EOL;
92-
$xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, $writer);
93-
$xmlWriter->save("{$name}.{$extension}");
94-
rename("{$name}.{$extension}", "results/{$name}.{$extension}");
88+
echo write($phpWord, basename(__FILE__, '.php'), $writers);
89+
if (!CLI) {
90+
include_once 'Sample_Footer.php';
9591
}
96-
97-
include_once 'Sample_Footer.php';

samples/Sample_10_EastAsianFontStyle.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,7 @@
1010
$section->addText('中文楷体样式测试',array('name' => '楷体', 'size' => 16, 'color' => '1B2232'));
1111

1212
// Save file
13-
$name = basename(__FILE__, '.php');
14-
$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf');
15-
foreach ($writers as $writer => $extension) {
16-
echo date('H:i:s'), " Write to {$writer} format", EOL;
17-
$xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, $writer);
18-
$xmlWriter->save("{$name}.{$extension}");
19-
rename("{$name}.{$extension}", "results/{$name}.{$extension}");
13+
echo write($phpWord, basename(__FILE__, '.php'), $writers);
14+
if (!CLI) {
15+
include_once 'Sample_Footer.php';
2016
}
21-
22-
include_once 'Sample_Footer.php';

0 commit comments

Comments
 (0)