diff --git a/samples/Sample_01_SimpleText.php b/samples/Sample_01_SimpleText.php index 55ffaf25..10f129db 100755 --- a/samples/Sample_01_SimpleText.php +++ b/samples/Sample_01_SimpleText.php @@ -45,7 +45,7 @@ $section->addLink('http://www.google.com', null, 'NLink'); $section->addTextBreak(); // Image -$section->addImage('old/_earth.jpg', array('width'=>18, 'height'=>18)); +$section->addImage('resources/_earth.jpg', array('width'=>18, 'height'=>18)); // Save file $name = basename(__FILE__, '.php'); diff --git a/samples/Sample_04_Textrun.php b/samples/Sample_04_Textrun.php index ce70417e..b30db7a5 100644 --- a/samples/Sample_04_Textrun.php +++ b/samples/Sample_04_Textrun.php @@ -32,7 +32,7 @@ $textrun->addText(' All elements are placed inside a paragraph with the optional $textrun->addText(' Sample Link: '); $textrun->addLink('http://www.google.com', null, 'NLink'); $textrun->addText(' Sample Image: '); -$textrun->addImage('old/_earth.jpg', array('width'=>18, 'height'=>18)); +$textrun->addImage('resources/_earth.jpg', array('width'=>18, 'height'=>18)); $textrun->addText(' Here is some more text. '); // Save file diff --git a/samples/Sample_14_ListItem.php b/samples/Sample_14_ListItem.php new file mode 100644 index 00000000..fa648784 --- /dev/null +++ b/samples/Sample_14_ListItem.php @@ -0,0 +1,66 @@ +'); +require_once '../Classes/PHPWord.php'; + +// New Word document +echo date('H:i:s'), " Create new PHPWord object", EOL; +$PHPWord = new PHPWord(); + +// Begin code +$section = $PHPWord->createSection(); + +// Add listitem elements +$section->addListItem('List Item 1', 0); +$section->addListItem('List Item 2', 0); +$section->addListItem('List Item 3', 0); +$section->addTextBreak(2); + +// Add listitem elements +$section->addListItem('List Item 1', 0); +$section->addListItem('List Item 1.1', 1); +$section->addListItem('List Item 1.2', 1); +$section->addListItem('List Item 1.3 (styled)', 1, array('bold'=>true)); +$section->addListItem('List Item 1.3.1', 2); +$section->addListItem('List Item 1.3.2', 2); +$section->addTextBreak(2); + +// Add listitem elements +$listStyle = array('listType'=>PHPWord_Style_ListItem::TYPE_NUMBER); +$section->addListItem('List Item 1', 0, null, $listStyle); +$section->addListItem('List Item 2', 0, null, $listStyle); +$section->addListItem('List Item 3', 0, null, $listStyle); +$section->addTextBreak(2); + +// Add listitem elements +$PHPWord->addFontStyle('myOwnStyle', array('color'=>'FF0000')); +$PHPWord->addParagraphStyle('P-Style', array('spaceAfter'=>95)); +$listStyle = array('listType'=>PHPWord_Style_ListItem::TYPE_NUMBER_NESTED); +$section->addListItem('List Item 1', 0, 'myOwnStyle', $listStyle, 'P-Style'); +$section->addListItem('List Item 2', 0, 'myOwnStyle', $listStyle, 'P-Style'); +$section->addListItem('List Item 3', 1, 'myOwnStyle', $listStyle, 'P-Style'); +$section->addListItem('List Item 4', 1, 'myOwnStyle', $listStyle, 'P-Style'); +$section->addListItem('List Item 5', 2, 'myOwnStyle', $listStyle, 'P-Style'); +$section->addListItem('List Item 6', 1, 'myOwnStyle', $listStyle, 'P-Style'); +$section->addListItem('List Item 7', 0, 'myOwnStyle', $listStyle, 'P-Style'); + +// End code + +// Save file +$name = basename(__FILE__, '.php'); +$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf'); +foreach ($writers as $writer => $extension) { + echo date('H:i:s'), " Write to {$writer} format", EOL; + $objWriter = PHPWord_IOFactory::createWriter($PHPWord, $writer); + $objWriter->save("{$name}.{$extension}"); + rename("{$name}.{$extension}", "results/{$name}.{$extension}"); +} + +// Done +echo date('H:i:s'), " Done writing file(s)", EOL; +echo date('H:i:s'), " Peak memory usage: ", (memory_get_peak_usage(true) / 1024 / 1024), " MB", EOL; diff --git a/samples/Sample_15_Link.php b/samples/Sample_15_Link.php new file mode 100644 index 00000000..ef631906 --- /dev/null +++ b/samples/Sample_15_Link.php @@ -0,0 +1,40 @@ +'); +require_once '../Classes/PHPWord.php'; + +// New Word document +echo date('H:i:s'), " Create new PHPWord object", EOL; +$PHPWord = new PHPWord(); + +// Begin code +$section = $PHPWord->createSection(); + +// Add hyperlink elements +$section->addLink('http://www.google.com', 'Best search engine', array('color'=>'0000FF', 'underline'=>PHPWord_Style_Font::UNDERLINE_SINGLE)); +$section->addTextBreak(2); + +$PHPWord->addLinkStyle('myOwnLinkStyle', array('bold'=>true, 'color'=>'808000')); +$section->addLink('http://www.bing.com', null, 'myOwnLinkStyle'); +$section->addLink('http://www.yahoo.com', null, 'myOwnLinkStyle'); + +// End code + +// Save file +$name = basename(__FILE__, '.php'); +$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf'); +foreach ($writers as $writer => $extension) { + echo date('H:i:s'), " Write to {$writer} format", EOL; + $objWriter = PHPWord_IOFactory::createWriter($PHPWord, $writer); + $objWriter->save("{$name}.{$extension}"); + rename("{$name}.{$extension}", "results/{$name}.{$extension}"); +} + +// Done +echo date('H:i:s'), " Done writing file(s)", EOL; +echo date('H:i:s'), " Peak memory usage: ", (memory_get_peak_usage(true) / 1024 / 1024), " MB", EOL; diff --git a/samples/Sample_16_Object.php b/samples/Sample_16_Object.php new file mode 100644 index 00000000..e04c49e5 --- /dev/null +++ b/samples/Sample_16_Object.php @@ -0,0 +1,35 @@ +'); +require_once '../Classes/PHPWord.php'; + +// New Word document +echo date('H:i:s'), " Create new PHPWord object", EOL; +$PHPWord = new PHPWord(); + +// Begin code +$section = $PHPWord->createSection(); +$section->addText('You can open this OLE object by double clicking on the icon:'); +$section->addTextBreak(2); +$section->addObject('resources/_sheet.xls'); + +// End code + +// Save file +$name = basename(__FILE__, '.php'); +$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf'); +foreach ($writers as $writer => $extension) { + echo date('H:i:s'), " Write to {$writer} format", EOL; + $objWriter = PHPWord_IOFactory::createWriter($PHPWord, $writer); + $objWriter->save("{$name}.{$extension}"); + rename("{$name}.{$extension}", "results/{$name}.{$extension}"); +} + +// Done +echo date('H:i:s'), " Done writing file(s)", EOL; +echo date('H:i:s'), " Peak memory usage: ", (memory_get_peak_usage(true) / 1024 / 1024), " MB", EOL; diff --git a/samples/Sample_17_TitleTOC.php b/samples/Sample_17_TitleTOC.php new file mode 100644 index 00000000..efa756e4 --- /dev/null +++ b/samples/Sample_17_TitleTOC.php @@ -0,0 +1,67 @@ +'); +require_once '../Classes/PHPWord.php'; + +// New Word document +echo date('H:i:s'), " Create new PHPWord object", EOL; +$PHPWord = new PHPWord(); + +// Begin code +$section = $PHPWord->createSection(); + +// Define the TOC font style +$fontStyle = array('spaceAfter'=>60, 'size'=>12); + +// Add title styles +$PHPWord->addTitleStyle(1, array('size'=>20, 'color'=>'333333', 'bold'=>true)); +$PHPWord->addTitleStyle(2, array('size'=>16, 'color'=>'666666')); + +// Add text elements +$section->addText('Table of contents:'); +$section->addTextBreak(2); + +// Add TOC +$section->addTOC($fontStyle); + +// Add Titles +$section->addPageBreak(); +$section->addTitle('I am Title 1', 1); +$section->addText('Some text...'); +$section->addTextBreak(2); + +$section->addTitle('I am a Subtitle of Title 1', 2); +$section->addTextBreak(2); +$section->addText('Some more text...'); +$section->addTextBreak(2); + +$section->addTitle('Another Title (Title 2)', 1); +$section->addText('Some text...'); +$section->addPageBreak(); +$section->addTitle('I am Title 3', 1); +$section->addText('And more text...'); +$section->addTextBreak(2); +$section->addTitle('I am a Subtitle of Title 3', 2); +$section->addText('Again and again, more text...'); + +echo date('H:i:s'), " Note: Please refresh TOC manually.", EOL; +// End code + +// Save file +$name = basename(__FILE__, '.php'); +$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf'); +foreach ($writers as $writer => $extension) { + echo date('H:i:s'), " Write to {$writer} format", EOL; + $objWriter = PHPWord_IOFactory::createWriter($PHPWord, $writer); + $objWriter->save("{$name}.{$extension}"); + rename("{$name}.{$extension}", "results/{$name}.{$extension}"); +} + +// Done +echo date('H:i:s'), " Done writing file(s)", EOL; +echo date('H:i:s'), " Peak memory usage: ", (memory_get_peak_usage(true) / 1024 / 1024), " MB", EOL; diff --git a/samples/Sample_18_Watermark.php b/samples/Sample_18_Watermark.php new file mode 100644 index 00000000..8332bd03 --- /dev/null +++ b/samples/Sample_18_Watermark.php @@ -0,0 +1,36 @@ +'); +require_once '../Classes/PHPWord.php'; + +// New Word document +echo date('H:i:s'), " Create new PHPWord object", EOL; +$PHPWord = new PHPWord(); + +// Begin code + +$section = $PHPWord->createSection(); +$header = $section->createHeader(); +$header->addWatermark('resources/_earth.jpg', array('marginTop' => 200, 'marginLeft' => 55)); +$section->addText('The header reference to the current section includes a watermark image.'); + +// End code + +// Save file +$name = basename(__FILE__, '.php'); +$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf'); +foreach ($writers as $writer => $extension) { + echo date('H:i:s'), " Write to {$writer} format", EOL; + $objWriter = PHPWord_IOFactory::createWriter($PHPWord, $writer); + $objWriter->save("{$name}.{$extension}"); + rename("{$name}.{$extension}", "results/{$name}.{$extension}"); +} + +// Done +echo date('H:i:s'), " Done writing file(s)", EOL; +echo date('H:i:s'), " Peak memory usage: ", (memory_get_peak_usage(true) / 1024 / 1024), " MB", EOL; diff --git a/samples/resources/_sheet.xls b/samples/resources/_sheet.xls new file mode 100644 index 00000000..6be0305d Binary files /dev/null and b/samples/resources/_sheet.xls differ