Skip to content

Commit b3458b9

Browse files
committed
Test & migrate the remaining old samples
1 parent ff6b2a9 commit b3458b9

File tree

8 files changed

+246
-2
lines changed

8 files changed

+246
-2
lines changed

samples/Sample_01_SimpleText.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
$section->addTextBreak();
4646

4747
// Image
48-
$section->addImage('old/_earth.jpg', array('width'=>18, 'height'=>18));
48+
$section->addImage('resources/_earth.jpg', array('width'=>18, 'height'=>18));
4949

5050
// Save file
5151
$name = basename(__FILE__, '.php');

samples/Sample_04_Textrun.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
$textrun->addText(' Sample Link: ');
3333
$textrun->addLink('http://www.google.com', null, 'NLink');
3434
$textrun->addText(' Sample Image: ');
35-
$textrun->addImage('old/_earth.jpg', array('width'=>18, 'height'=>18));
35+
$textrun->addImage('resources/_earth.jpg', array('width'=>18, 'height'=>18));
3636
$textrun->addText(' Here is some more text. ');
3737

3838
// Save file

samples/Sample_14_ListItem.php

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
/**
3+
* List item sample
4+
*/
5+
6+
// Init
7+
error_reporting(E_ALL);
8+
define('EOL', (PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
9+
require_once '../Classes/PHPWord.php';
10+
11+
// New Word document
12+
echo date('H:i:s'), " Create new PHPWord object", EOL;
13+
$PHPWord = new PHPWord();
14+
15+
// Begin code
16+
$section = $PHPWord->createSection();
17+
18+
// Add listitem elements
19+
$section->addListItem('List Item 1', 0);
20+
$section->addListItem('List Item 2', 0);
21+
$section->addListItem('List Item 3', 0);
22+
$section->addTextBreak(2);
23+
24+
// Add listitem elements
25+
$section->addListItem('List Item 1', 0);
26+
$section->addListItem('List Item 1.1', 1);
27+
$section->addListItem('List Item 1.2', 1);
28+
$section->addListItem('List Item 1.3 (styled)', 1, array('bold'=>true));
29+
$section->addListItem('List Item 1.3.1', 2);
30+
$section->addListItem('List Item 1.3.2', 2);
31+
$section->addTextBreak(2);
32+
33+
// Add listitem elements
34+
$listStyle = array('listType'=>PHPWord_Style_ListItem::TYPE_NUMBER);
35+
$section->addListItem('List Item 1', 0, null, $listStyle);
36+
$section->addListItem('List Item 2', 0, null, $listStyle);
37+
$section->addListItem('List Item 3', 0, null, $listStyle);
38+
$section->addTextBreak(2);
39+
40+
// Add listitem elements
41+
$PHPWord->addFontStyle('myOwnStyle', array('color'=>'FF0000'));
42+
$PHPWord->addParagraphStyle('P-Style', array('spaceAfter'=>95));
43+
$listStyle = array('listType'=>PHPWord_Style_ListItem::TYPE_NUMBER_NESTED);
44+
$section->addListItem('List Item 1', 0, 'myOwnStyle', $listStyle, 'P-Style');
45+
$section->addListItem('List Item 2', 0, 'myOwnStyle', $listStyle, 'P-Style');
46+
$section->addListItem('List Item 3', 1, 'myOwnStyle', $listStyle, 'P-Style');
47+
$section->addListItem('List Item 4', 1, 'myOwnStyle', $listStyle, 'P-Style');
48+
$section->addListItem('List Item 5', 2, 'myOwnStyle', $listStyle, 'P-Style');
49+
$section->addListItem('List Item 6', 1, 'myOwnStyle', $listStyle, 'P-Style');
50+
$section->addListItem('List Item 7', 0, 'myOwnStyle', $listStyle, 'P-Style');
51+
52+
// End code
53+
54+
// Save file
55+
$name = basename(__FILE__, '.php');
56+
$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf');
57+
foreach ($writers as $writer => $extension) {
58+
echo date('H:i:s'), " Write to {$writer} format", EOL;
59+
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, $writer);
60+
$objWriter->save("{$name}.{$extension}");
61+
rename("{$name}.{$extension}", "results/{$name}.{$extension}");
62+
}
63+
64+
// Done
65+
echo date('H:i:s'), " Done writing file(s)", EOL;
66+
echo date('H:i:s'), " Peak memory usage: ", (memory_get_peak_usage(true) / 1024 / 1024), " MB", EOL;

samples/Sample_15_Link.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
/**
3+
* Link sample
4+
*/
5+
6+
// Init
7+
error_reporting(E_ALL);
8+
define('EOL', (PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
9+
require_once '../Classes/PHPWord.php';
10+
11+
// New Word document
12+
echo date('H:i:s'), " Create new PHPWord object", EOL;
13+
$PHPWord = new PHPWord();
14+
15+
// Begin code
16+
$section = $PHPWord->createSection();
17+
18+
// Add hyperlink elements
19+
$section->addLink('http://www.google.com', 'Best search engine', array('color'=>'0000FF', 'underline'=>PHPWord_Style_Font::UNDERLINE_SINGLE));
20+
$section->addTextBreak(2);
21+
22+
$PHPWord->addLinkStyle('myOwnLinkStyle', array('bold'=>true, 'color'=>'808000'));
23+
$section->addLink('http://www.bing.com', null, 'myOwnLinkStyle');
24+
$section->addLink('http://www.yahoo.com', null, 'myOwnLinkStyle');
25+
26+
// End code
27+
28+
// 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+
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, $writer);
34+
$objWriter->save("{$name}.{$extension}");
35+
rename("{$name}.{$extension}", "results/{$name}.{$extension}");
36+
}
37+
38+
// Done
39+
echo date('H:i:s'), " Done writing file(s)", EOL;
40+
echo date('H:i:s'), " Peak memory usage: ", (memory_get_peak_usage(true) / 1024 / 1024), " MB", EOL;

samples/Sample_16_Object.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
/**
3+
* Object sample
4+
*/
5+
6+
// Init
7+
error_reporting(E_ALL);
8+
define('EOL', (PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
9+
require_once '../Classes/PHPWord.php';
10+
11+
// New Word document
12+
echo date('H:i:s'), " Create new PHPWord object", EOL;
13+
$PHPWord = new PHPWord();
14+
15+
// Begin code
16+
$section = $PHPWord->createSection();
17+
$section->addText('You can open this OLE object by double clicking on the icon:');
18+
$section->addTextBreak(2);
19+
$section->addObject('resources/_sheet.xls');
20+
21+
// End code
22+
23+
// Save file
24+
$name = basename(__FILE__, '.php');
25+
$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf');
26+
foreach ($writers as $writer => $extension) {
27+
echo date('H:i:s'), " Write to {$writer} format", EOL;
28+
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, $writer);
29+
$objWriter->save("{$name}.{$extension}");
30+
rename("{$name}.{$extension}", "results/{$name}.{$extension}");
31+
}
32+
33+
// Done
34+
echo date('H:i:s'), " Done writing file(s)", EOL;
35+
echo date('H:i:s'), " Peak memory usage: ", (memory_get_peak_usage(true) / 1024 / 1024), " MB", EOL;

samples/Sample_17_TitleTOC.php

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
/**
3+
* Generic template for creating PHPWord samples
4+
*/
5+
6+
// Init
7+
error_reporting(E_ALL);
8+
define('EOL', (PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
9+
require_once '../Classes/PHPWord.php';
10+
11+
// New Word document
12+
echo date('H:i:s'), " Create new PHPWord object", EOL;
13+
$PHPWord = new PHPWord();
14+
15+
// Begin code
16+
$section = $PHPWord->createSection();
17+
18+
// Define the TOC font style
19+
$fontStyle = array('spaceAfter'=>60, 'size'=>12);
20+
21+
// Add title styles
22+
$PHPWord->addTitleStyle(1, array('size'=>20, 'color'=>'333333', 'bold'=>true));
23+
$PHPWord->addTitleStyle(2, array('size'=>16, 'color'=>'666666'));
24+
25+
// Add text elements
26+
$section->addText('Table of contents:');
27+
$section->addTextBreak(2);
28+
29+
// Add TOC
30+
$section->addTOC($fontStyle);
31+
32+
// Add Titles
33+
$section->addPageBreak();
34+
$section->addTitle('I am Title 1', 1);
35+
$section->addText('Some text...');
36+
$section->addTextBreak(2);
37+
38+
$section->addTitle('I am a Subtitle of Title 1', 2);
39+
$section->addTextBreak(2);
40+
$section->addText('Some more text...');
41+
$section->addTextBreak(2);
42+
43+
$section->addTitle('Another Title (Title 2)', 1);
44+
$section->addText('Some text...');
45+
$section->addPageBreak();
46+
$section->addTitle('I am Title 3', 1);
47+
$section->addText('And more text...');
48+
$section->addTextBreak(2);
49+
$section->addTitle('I am a Subtitle of Title 3', 2);
50+
$section->addText('Again and again, more text...');
51+
52+
echo date('H:i:s'), " Note: Please refresh TOC manually.", EOL;
53+
// End code
54+
55+
// Save file
56+
$name = basename(__FILE__, '.php');
57+
$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf');
58+
foreach ($writers as $writer => $extension) {
59+
echo date('H:i:s'), " Write to {$writer} format", EOL;
60+
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, $writer);
61+
$objWriter->save("{$name}.{$extension}");
62+
rename("{$name}.{$extension}", "results/{$name}.{$extension}");
63+
}
64+
65+
// Done
66+
echo date('H:i:s'), " Done writing file(s)", EOL;
67+
echo date('H:i:s'), " Peak memory usage: ", (memory_get_peak_usage(true) / 1024 / 1024), " MB", EOL;

samples/Sample_18_Watermark.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
/**
3+
* Generic template for creating PHPWord samples
4+
*/
5+
6+
// Init
7+
error_reporting(E_ALL);
8+
define('EOL', (PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
9+
require_once '../Classes/PHPWord.php';
10+
11+
// New Word document
12+
echo date('H:i:s'), " Create new PHPWord object", EOL;
13+
$PHPWord = new PHPWord();
14+
15+
// Begin code
16+
17+
$section = $PHPWord->createSection();
18+
$header = $section->createHeader();
19+
$header->addWatermark('resources/_earth.jpg', array('marginTop' => 200, 'marginLeft' => 55));
20+
$section->addText('The header reference to the current section includes a watermark image.');
21+
22+
// End code
23+
24+
// Save file
25+
$name = basename(__FILE__, '.php');
26+
$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf');
27+
foreach ($writers as $writer => $extension) {
28+
echo date('H:i:s'), " Write to {$writer} format", EOL;
29+
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, $writer);
30+
$objWriter->save("{$name}.{$extension}");
31+
rename("{$name}.{$extension}", "results/{$name}.{$extension}");
32+
}
33+
34+
// Done
35+
echo date('H:i:s'), " Done writing file(s)", EOL;
36+
echo date('H:i:s'), " Peak memory usage: ", (memory_get_peak_usage(true) / 1024 / 1024), " MB", EOL;

samples/resources/_sheet.xls

13.5 KB
Binary file not shown.

0 commit comments

Comments
 (0)