diff --git a/Classes/PHPWord/Media.php b/Classes/PHPWord/Media.php index 28d3d033..82294132 100755 --- a/Classes/PHPWord/Media.php +++ b/Classes/PHPWord/Media.php @@ -86,11 +86,14 @@ class PHPWord_Media $file = null; if ($type === 'image') { $cImg++; + //Detect if it's a memory image first by php ext and second by regex $isMemImage = false; if (stripos(strrev($src), strrev('.php')) === 0) { $isMemImage = true; } - + if (!$isMemImage) { + $isMemImage = (filter_var($src, FILTER_VALIDATE_URL) !== false); + } $extension = ''; if ($isMemImage) { $extension = $memoryImage->getImageExtension(); diff --git a/Classes/PHPWord/Writer/Word2007/Base.php b/Classes/PHPWord/Writer/Word2007/Base.php index f1324253..0168a649 100755 --- a/Classes/PHPWord/Writer/Word2007/Base.php +++ b/Classes/PHPWord/Writer/Word2007/Base.php @@ -751,9 +751,9 @@ class PHPWord_Writer_Word2007_Base extends PHPWord_Writer_Word2007_WriterPart /** * @param \PHPWord_Shared_XMLWriter $objWriter - * @param \PHPWord_Section_Image $image + * @param \PHPWord_Section_Image|\PHPWord_Section_MemoryImage $image */ - protected function _writeImage(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_Image $image, $withoutP = false) + protected function _writeImage(PHPWord_Shared_XMLWriter $objWriter = null, $image, $withoutP = false) { $rId = $image->getRelationId(); diff --git a/Classes/PHPWord/Writer/Word2007/ContentTypes.php b/Classes/PHPWord/Writer/Word2007/ContentTypes.php index 56a33d69..1d81038f 100755 --- a/Classes/PHPWord/Writer/Word2007/ContentTypes.php +++ b/Classes/PHPWord/Writer/Word2007/ContentTypes.php @@ -138,6 +138,13 @@ class PHPWord_Writer_Word2007_ContentTypes extends PHPWord_Writer_Word2007_Write 'application/vnd.openxmlformats-officedocument.wordprocessingml.fontTable+xml' ); + // Footnotes + $this->_writeOverrideContentType( + $objWriter, + '/word/footnotes.xml', + 'application/vnd.openxmlformats-officedocument.wordprocessingml.footnotes+xml' + ); + for ($i = 1; $i <= $_cHdrs; $i++) { $this->_writeOverrideContentType( $objWriter, diff --git a/Tests/PHPWord/SettingsTest.php b/Tests/PHPWord/SettingsTest.php new file mode 100644 index 00000000..e61a2129 --- /dev/null +++ b/Tests/PHPWord/SettingsTest.php @@ -0,0 +1,26 @@ +assertTrue(PHPWord_Settings::getCompatibility()); + $this->assertTrue(PHPWord_Settings::setCompatibility(false)); + $this->assertFalse(PHPWord_Settings::getCompatibility()); + $this->assertFalse(PHPWord_Settings::setCompatibility('Non boolean')); + } +} diff --git a/Tests/PHPWord/StyleTest.php b/Tests/PHPWord/StyleTest.php index 36e961ac..9e442cb1 100644 --- a/Tests/PHPWord/StyleTest.php +++ b/Tests/PHPWord/StyleTest.php @@ -1,7 +1,6 @@ createSection(); + $header = $section->createHeader(); + $header->addWatermark($imageSrc); + $doc = TestHelperDOCX::getDocument($PHPWord); + + $element = $doc->getElement("/w:document/w:body/w:sectPr/w:headerReference"); + $this->assertStringStartsWith("rId", $element->getAttribute('r:id')); + } + + /** + * covers ::_writeTitle */ public function testWriteTitle() { diff --git a/Tests/PHPWord/Writer/Word2007/DocumentTest.php b/Tests/PHPWord/Writer/Word2007/DocumentTest.php index 7d06085a..fe854fee 100644 --- a/Tests/PHPWord/Writer/Word2007/DocumentTest.php +++ b/Tests/PHPWord/Writer/Word2007/DocumentTest.php @@ -32,4 +32,56 @@ class DocumentTest extends \PHPUnit_Framework_TestCase $this->assertEquals(2, $element->getAttribute('w:start')); } + + /** + * covers ::_writeTOC + * covers ::_writePageBreak + * covers ::_writeListItem + * covers ::_writeTitle + * covers ::_writeObject + */ + public function testElements() + { + $objectSrc = join( + DIRECTORY_SEPARATOR, + array(PHPWORD_TESTS_DIR_ROOT, '_files', 'documents', 'sheet.xls') + ); + + $PHPWord = new PHPWord(); + $PHPWord->addTitleStyle(1, array('color' => '333333', 'bold'=>true)); + $PHPWord->addTitleStyle(2, array('color'=>'666666')); + $section = $PHPWord->createSection(); + $section->addTOC(); + $section->addPageBreak(); + $section->addTitle('Title 1', 1); + $section->addListItem('List Item 1', 0); + $section->addListItem('List Item 2', 0); + $section->addListItem('List Item 3', 0); + $section = $PHPWord->createSection(); + $section->addTitle('Title 2', 2); + $section->addObject($objectSrc); + $doc = TestHelperDOCX::getDocument($PHPWord); + + // TOC + $element = $doc->getElement('/w:document/w:body/w:p[1]/w:pPr/w:tabs/w:tab'); + $this->assertEquals('right', $element->getAttribute('w:val')); + $this->assertEquals('dot', $element->getAttribute('w:leader')); + $this->assertEquals(9062, $element->getAttribute('w:pos')); + + // Page break + $element = $doc->getElement('/w:document/w:body/w:p[4]/w:r/w:br'); + $this->assertEquals('page', $element->getAttribute('w:type')); + + // Title + $element = $doc->getElement('/w:document/w:body/w:p[5]/w:pPr/w:pStyle'); + $this->assertEquals('Heading1', $element->getAttribute('w:val')); + + // List item + $element = $doc->getElement('/w:document/w:body/w:p[6]/w:pPr/w:numPr/w:numId'); + $this->assertEquals(3, $element->getAttribute('w:val')); + + // Object + $element = $doc->getElement('/w:document/w:body/w:p[11]/w:r/w:object/o:OLEObject'); + $this->assertEquals('Embed', $element->getAttribute('Type')); + } } diff --git a/Tests/PHPWord/Writer/Word2007/FootnotesTest.php b/Tests/PHPWord/Writer/Word2007/FootnotesTest.php new file mode 100644 index 00000000..ea49bd67 --- /dev/null +++ b/Tests/PHPWord/Writer/Word2007/FootnotesTest.php @@ -0,0 +1,34 @@ +createSection(); + $section->addText('Text'); + $footnote = $section->createFootnote(); + $footnote->addText('Footnote'); + $footnote->addLink('http://google.com'); + $doc = TestHelperDOCX::getDocument($PHPWord); + + $this->assertTrue($doc->elementExists("/w:document/w:body/w:p/w:r/w:footnoteReference")); + } +} diff --git a/Tests/PHPWord/Writer/Word2007/StylesTest.php b/Tests/PHPWord/Writer/Word2007/StylesTest.php index fe129f11..bcdc4b81 100644 --- a/Tests/PHPWord/Writer/Word2007/StylesTest.php +++ b/Tests/PHPWord/Writer/Word2007/StylesTest.php @@ -26,13 +26,31 @@ class StylesTest extends \PHPUnit_Framework_TestCase { $PHPWord = new PHPWord(); - $defaultStyle = array('align' => 'both'); - $baseStyle = array('basedOn' => 'Normal'); - $newStyle = array('basedOn' => 'Base Style', 'next' => 'Normal'); - $PHPWord->setDefaultParagraphStyle($defaultStyle); - $PHPWord->addParagraphStyle('Base Style', $baseStyle); - $PHPWord->addParagraphStyle('New Style', $newStyle); + $pStyle = array('align' => 'both'); + $pBase = array('basedOn' => 'Normal'); + $pNew = array('basedOn' => 'Base Style', 'next' => 'Normal'); + $rStyle = array('size' => 20); + $tStyle = array( + 'bgColor' => 'FF0000', + 'cellMarginTop' => 120, + 'cellMarginBottom' => 120, + 'cellMarginLeft' => 120, + 'cellMarginRight' => 120, + 'borderTopSize' => 120, + 'borderBottomSize' => 120, + 'borderLeftSize' => 120, + 'borderRightSize' => 120, + 'borderInsideHSize' => 120, + 'borderInsideVSize' => 120, + ); + $PHPWord->setDefaultParagraphStyle($pStyle); + $PHPWord->addParagraphStyle('Base Style', $pBase); + $PHPWord->addParagraphStyle('New Style', $pNew); + $PHPWord->addFontStyle('New Style', $rStyle, $pStyle); + $PHPWord->addTableStyle('Table Style', $tStyle, $tStyle); + $PHPWord->addTitleStyle(1, $rStyle, $pStyle); $doc = TestHelperDOCX::getDocument($PHPWord); + $file = 'word/styles.xml'; // Normal style generated? diff --git a/changelog.txt b/changelog.txt index a76efb00..a75fa93c 100755 --- a/changelog.txt +++ b/changelog.txt @@ -51,6 +51,7 @@ Changes in branch for release 0.7.1 : - Feature: (ivanlanin) - Paragraph: setTabs() function - Feature: (ivanlanin) GH-99 - General: Basic support for TextRun on ODT and RTF - Feature: (ivanlanin) - Reader: Initial effort for Word2007 +- Feature: (ivanlanin) - MemoryImage: Allow remote image when allow_url_open = on - QA: (Progi1984) - UnitTests Changes in branch for release 0.7.0 : 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/old/HeaderFooter.php b/samples/Sample_12_HeaderFooter.php old mode 100755 new mode 100644 similarity index 55% rename from samples/old/HeaderFooter.php rename to samples/Sample_12_HeaderFooter.php index ae3ce5ac..b0d0e137 --- a/samples/old/HeaderFooter.php +++ b/samples/Sample_12_HeaderFooter.php @@ -1,7 +1,11 @@ '); +require_once '../Classes/PHPWord.php'; -// New Word Document +// New Word document +echo date('H:i:s') , " Create new PHPWord object" , EOL; $PHPWord = new PHPWord(); // New portrait section @@ -13,7 +17,10 @@ $header->firstPage(); $table = $header->addTable(); $table->addRow(); $table->addCell(4500)->addText('This is the header.'); -$table->addCell(4500)->addImage('_earth.jpg', array('width'=>50, 'height'=>50, 'align'=>'right')); +$table->addCell(4500)->addImage( + 'resources/PHPWord.png', + array('width' => 80, 'height' => 80, 'align' => 'right') +); // Add header for all other pages $subsequent = $section->createHeader(); @@ -21,7 +28,7 @@ $subsequent->addText("Subsequent pages in Section 1 will Have this!"); // Add footer $footer = $section->createFooter(); -$footer->addPreserveText('Page {PAGE} of {NUMPAGES}.', array('align'=>'center')); +$footer->addPreserveText('Page {PAGE} of {NUMPAGES}.', array('align' => 'center')); // Write some text $section->addTextBreak(); @@ -51,6 +58,17 @@ $sec2Header->addText("All pages in Section 2 will Have this!"); $section2->addTextBreak(); $section2->addText('Some text...'); -// Save File -$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007'); -$objWriter->save('HeaderFooter.docx'); + +// 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_13_Images.php b/samples/Sample_13_Images.php new file mode 100644 index 00000000..0f64cb7b --- /dev/null +++ b/samples/Sample_13_Images.php @@ -0,0 +1,42 @@ +'); +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('Local image without any styles:'); +$section->addImage('resources/_mars.jpg'); +$section->addTextBreak(2); +// +$section->addText('Local image with styles:'); +$section->addImage('resources/_earth.jpg', array('width' => 210, 'height' => 210, 'align' => 'center')); +$section->addTextBreak(2); + +$source = 'http://php.net/images/logos/php-med-trans-light.gif'; +$section->addText("Remote image from: {$source}"); +$section->addMemoryImage($source); +// 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/old/ListItem.php b/samples/Sample_14_ListItem.php old mode 100755 new mode 100644 similarity index 66% rename from samples/old/ListItem.php rename to samples/Sample_14_ListItem.php index e0125980..fa648784 --- a/samples/old/ListItem.php +++ b/samples/Sample_14_ListItem.php @@ -1,10 +1,18 @@ '); +require_once '../Classes/PHPWord.php'; + +// New Word document +echo date('H:i:s'), " Create new PHPWord object", EOL; $PHPWord = new PHPWord(); -// New portrait section +// Begin code $section = $PHPWord->createSection(); // Add listitem elements @@ -41,6 +49,18 @@ $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'); -// Save File -$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007'); -$objWriter->save('ListItem.docx'); +// 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/old/TitleTOC.php b/samples/Sample_17_TitleTOC.php old mode 100755 new mode 100644 similarity index 53% rename from samples/old/TitleTOC.php rename to samples/Sample_17_TitleTOC.php index 376d26e8..efa756e4 --- a/samples/old/TitleTOC.php +++ b/samples/Sample_17_TitleTOC.php @@ -1,10 +1,18 @@ '); +require_once '../Classes/PHPWord.php'; + +// New Word document +echo date('H:i:s'), " Create new PHPWord object", EOL; $PHPWord = new PHPWord(); -// New portrait section +// Begin code $section = $PHPWord->createSection(); // Define the TOC font style @@ -41,8 +49,19 @@ $section->addTextBreak(2); $section->addTitle('I am a Subtitle of Title 3', 2); $section->addText('Again and again, more text...'); -echo 'Note: The pagenumbers in the TOC doesnt refresh automatically.'; +echo date('H:i:s'), " Note: Please refresh TOC manually.", EOL; +// End code -// Save File -$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007'); -$objWriter->save('TitleTOC.docx'); +// 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/old/AdvancedTable.php b/samples/old/AdvancedTable.php deleted file mode 100755 index 021cd920..00000000 --- a/samples/old/AdvancedTable.php +++ /dev/null @@ -1,52 +0,0 @@ -createSection(); - -// Define table style arrays -$styleTable = array('borderSize'=>6, 'borderColor'=>'006699', 'cellMargin'=>80); -$styleFirstRow = array('borderBottomSize'=>18, 'borderBottomColor'=>'0000FF', 'bgColor'=>'66BBFF'); - -// Define cell style arrays -$styleCell = array('valign'=>'center'); -$styleCellBTLR = array('valign'=>'center', 'textDirection'=>PHPWord_Style_Cell::TEXT_DIR_BTLR); - -// Define font style for first row -$fontStyle = array('bold'=>true, 'align'=>'center'); - -// Add table style -$PHPWord->addTableStyle('myOwnTableStyle', $styleTable, $styleFirstRow); - -// Add table -$table = $section->addTable('myOwnTableStyle'); - -// Add row -$table->addRow(900); - -// Add cells -$table->addCell(2000, $styleCell)->addText('Row 1', $fontStyle); -$table->addCell(2000, $styleCell)->addText('Row 2', $fontStyle); -$table->addCell(2000, $styleCell)->addText('Row 3', $fontStyle); -$table->addCell(2000, $styleCell)->addText('Row 4', $fontStyle); -$table->addCell(500, $styleCellBTLR)->addText('Row 5', $fontStyle); - -// Add more rows / cells -for($i = 1; $i <= 10; $i++) { - $table->addRow(); - $table->addCell(2000)->addText("Cell $i"); - $table->addCell(2000)->addText("Cell $i"); - $table->addCell(2000)->addText("Cell $i"); - $table->addCell(2000)->addText("Cell $i"); - - $text = ($i % 2 == 0) ? 'X' : ''; - $table->addCell(500)->addText($text); -} - - -// Save File -$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007'); -$objWriter->save('AdvancedTable.docx'); diff --git a/samples/old/BasicTable.php b/samples/old/BasicTable.php deleted file mode 100755 index 6bd8336a..00000000 --- a/samples/old/BasicTable.php +++ /dev/null @@ -1,25 +0,0 @@ -createSection(); - -// Add table -$table = $section->addTable(); - -for($r = 1; $r <= 10; $r++) { // Loop through rows - // Add row - $table->addRow(); - - for($c = 1; $c <= 5; $c++) { // Loop through cells - // Add Cell - $table->addCell(1750)->addText("Row $r, Cell $c"); - } -} - -// Save File -$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007'); -$objWriter->save('BasicTable.docx'); diff --git a/samples/old/Image.php b/samples/old/Image.php deleted file mode 100755 index 5018e206..00000000 --- a/samples/old/Image.php +++ /dev/null @@ -1,23 +0,0 @@ -createSection(); - -// Add image elements -$section->addImage('_mars.jpg'); -$section->addTextBreak(2); - -$section->addImage('_earth.jpg', array('width'=>210, 'height'=>210, 'align'=>'center')); -$section->addTextBreak(2); - -$section->addImage('_mars.jpg', array('width'=>100, 'height'=>100, 'align'=>'right')); - - - -// Save File -$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007'); -$objWriter->save('Image.docx'); diff --git a/samples/old/Link.php b/samples/old/Link.php deleted file mode 100755 index 8ad5575e..00000000 --- a/samples/old/Link.php +++ /dev/null @@ -1,23 +0,0 @@ -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'); - - - - -// Save File -$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007'); -$objWriter->save('Link.docx'); diff --git a/samples/old/Object.php b/samples/old/Object.php deleted file mode 100755 index b54df971..00000000 --- a/samples/old/Object.php +++ /dev/null @@ -1,19 +0,0 @@ -createSection(); - -// Add text elements -$section->addText('You can open this OLE object by double clicking on the icon:'); -$section->addTextBreak(2); - -// Add object -$section->addObject('_sheet.xls'); - -// Save File -$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007'); -$objWriter->save('Object.docx'); diff --git a/samples/old/Section.php b/samples/old/Section.php deleted file mode 100755 index 875e9fc2..00000000 --- a/samples/old/Section.php +++ /dev/null @@ -1,25 +0,0 @@ -createSection(array('borderColor'=>'00FF00', 'borderSize'=>12)); -$section->addText('I am placed on a default section.'); - -// New landscape section -$section = $PHPWord->createSection(array('orientation'=>'landscape')); -$section->addText('I am placed on a landscape section. Every page starting from this section will be landscape style.'); -$section->addPageBreak(); -$section->addPageBreak(); - -// New portrait section -$section = $PHPWord->createSection(array('marginLeft'=>600, 'marginRight'=>600, 'marginTop'=>600, 'marginBottom'=>600)); -$section->addText('This section uses other margins.'); - - - -// Save File -$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007'); -$objWriter->save('Section.docx'); diff --git a/samples/old/Template.php b/samples/old/Template.php deleted file mode 100755 index 1b4472b1..00000000 --- a/samples/old/Template.php +++ /dev/null @@ -1,22 +0,0 @@ -loadTemplate('Template.docx'); - -$document->setValue('Value1', 'Sun'); -$document->setValue('Value2', 'Mercury'); -$document->setValue('Value3', 'Venus'); -$document->setValue('Value4', 'Earth'); -$document->setValue('Value5', 'Mars'); -$document->setValue('Value6', 'Jupiter'); -$document->setValue('Value7', 'Saturn'); -$document->setValue('Value8', 'Uranus'); -$document->setValue('Value9', 'Neptun'); -$document->setValue('Value10', 'Pluto'); - -$document->setValue('weekday', date('l')); -$document->setValue('time', date('H:i')); - -$document->save('Solarsystem.docx'); diff --git a/samples/old/Textrun.php b/samples/old/Textrun.php deleted file mode 100755 index 3fa12d97..00000000 --- a/samples/old/Textrun.php +++ /dev/null @@ -1,31 +0,0 @@ -createSection(); - -// 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'=>PHPWord_Style_Font::UNDERLINE_SINGLE)); - -// Add text elements -$textrun = $section->createTextRun('pStyle'); - -$textrun->addText('Each textrun can contain native text or link elements.'); -$textrun->addText(' No break is placed after adding an element.', 'BoldText'); -$textrun->addText(' All elements are placed inside a paragraph with the optionally given p-Style.', 'ColoredText'); -$textrun->addText(' The best search engine: '); -$textrun->addLink('http://www.google.com', null, 'NLink'); -$textrun->addText('. Also not bad: '); -$textrun->addLink('http://www.bing.com', null, 'NLink'); - - - -// Save File -$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007'); -$objWriter->save('Textrun.docx'); diff --git a/samples/old/Watermark.php b/samples/old/Watermark.php deleted file mode 100755 index 319221c1..00000000 --- a/samples/old/Watermark.php +++ /dev/null @@ -1,20 +0,0 @@ -createSection(); - -// Create header -$header = $section->createHeader(); - -// Add a watermark to the header -$header->addWatermark('_earth.jpg', array('marginTop'=>200, 'marginLeft'=>55)); - -$section->addText('The header reference to the current section includes a watermark image.'); - -// Save File -$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007'); -$objWriter->save('Watermark.docx'); diff --git a/samples/resources/PHPWord.png b/samples/resources/PHPWord.png new file mode 100644 index 00000000..9b7f4930 Binary files /dev/null and b/samples/resources/PHPWord.png differ diff --git a/samples/old/_earth.jpg b/samples/resources/_earth.jpg similarity index 100% rename from samples/old/_earth.jpg rename to samples/resources/_earth.jpg diff --git a/samples/old/_mars.jpg b/samples/resources/_mars.jpg similarity index 100% rename from samples/old/_mars.jpg rename to samples/resources/_mars.jpg diff --git a/samples/old/_sheet.xls b/samples/resources/_sheet.xls similarity index 86% rename from samples/old/_sheet.xls rename to samples/resources/_sheet.xls index b8da43c6..6be0305d 100644 Binary files a/samples/old/_sheet.xls and b/samples/resources/_sheet.xls differ