Merge pull request #122 from ivanlanin/develop

Allow adding MemoryImage using URL
This commit is contained in:
Progi1984 2014-03-13 22:56:32 +01:00
commit 645d237582
32 changed files with 415 additions and 282 deletions

View File

@ -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();

View File

@ -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();

View File

@ -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,

View File

@ -0,0 +1,26 @@
<?php
namespace PHPWord\Tests;
use PHPWord_Settings;
/**
* Class TOCTest
*
* @package PHPWord\Tests
* @covers PHPWord_Settings
* @runTestsInSeparateProcesses
*/
class SettingsTest extends \PHPUnit_Framework_TestCase
{
/**
* @covers PHPWord_Settings::setCompatibility
* @covers PHPWord_Settings::getCompatibility
*/
public function testGetSetCompatibility()
{
$this->assertTrue(PHPWord_Settings::getCompatibility());
$this->assertTrue(PHPWord_Settings::setCompatibility(false));
$this->assertFalse(PHPWord_Settings::getCompatibility());
$this->assertFalse(PHPWord_Settings::setCompatibility('Non boolean'));
}
}

View File

@ -1,7 +1,6 @@
<?php
namespace PHPWord\Tests;
use PHPUnit_Framework_TestCase;
use PHPWord_Style;
/**
@ -11,7 +10,7 @@ use PHPWord_Style;
* @covers PHPWord_Style
* @runTestsInSeparateProcesses
*/
class StyleTest extends PHPUnit_Framework_TestCase
class StyleTest extends \PHPUnit_Framework_TestCase
{
/**
* @covers PHPWord_Style::addParagraphStyle

View File

@ -21,6 +21,9 @@ class BaseTest extends \PHPUnit_Framework_TestCase
TestHelperDOCX::clear();
}
/**
* covers ::_writeText
*/
public function testWriteText()
{
$rStyle = 'rStyle';
@ -40,7 +43,7 @@ class BaseTest extends \PHPUnit_Framework_TestCase
}
/**
* Write text run
* covers ::_writeTextRun
*/
public function testWriteTextRun()
{
@ -67,7 +70,7 @@ class BaseTest extends \PHPUnit_Framework_TestCase
}
/**
* Write link
* covers ::_writeLink
*/
public function testWriteLink()
{
@ -84,7 +87,7 @@ class BaseTest extends \PHPUnit_Framework_TestCase
}
/**
* Write preserve text
* covers ::_writePreserveText
*/
public function testWritePreserveText()
{
@ -102,7 +105,7 @@ class BaseTest extends \PHPUnit_Framework_TestCase
}
/**
* Write paragraph style: Alignment
* covers ::_writeParagraphStyle
*/
public function testWriteParagraphStyleAlign()
{
@ -118,7 +121,7 @@ class BaseTest extends \PHPUnit_Framework_TestCase
}
/**
* Write paragraph style: Pagination
* covers ::_writeParagraphStyle
*/
public function testWriteParagraphStylePagination()
{
@ -180,7 +183,7 @@ class BaseTest extends \PHPUnit_Framework_TestCase
}
/**
* Write table
* covers ::_writeTableStyle
*/
public function testWriteTableStyle()
{
@ -238,7 +241,7 @@ class BaseTest extends \PHPUnit_Framework_TestCase
}
/**
* Write cell style
* covers ::_writeCellStyle
*/
public function testWriteCellStyleCellGridSpan()
{
@ -265,7 +268,7 @@ class BaseTest extends \PHPUnit_Framework_TestCase
}
/**
* Write image
* covers ::_writeImage
*/
public function testWriteImagePosition()
{
@ -290,7 +293,27 @@ class BaseTest extends \PHPUnit_Framework_TestCase
}
/**
* Write title
* covers ::_writeWatermark
*/
public function testWriteWatermark()
{
$imageSrc = join(
DIRECTORY_SEPARATOR,
array(PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'earth.jpg')
);
$PHPWord = new PHPWord();
$section = $PHPWord->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()
{

View File

@ -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'));
}
}

View File

@ -0,0 +1,34 @@
<?php
namespace PHPWord\Tests\Writer\Word2007;
use PHPWord;
use PHPWord\Tests\TestHelperDOCX;
/**
* Class PHPWord_Writer_Word2007_FootnotesTest
* @package PHPWord\Tests
* @runTestsInSeparateProcesses
*/
class FootnotesTest extends \PHPUnit_Framework_TestCase
{
/**
* Executed before each method of the class
*/
public function tearDown()
{
TestHelperDOCX::clear();
}
public function testWriteFootnotes()
{
$PHPWord = new PHPWord();
$section = $PHPWord->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"));
}
}

View File

@ -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?

View File

@ -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 :

View File

@ -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');

View File

@ -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

View File

@ -1,7 +1,11 @@
<?php
require_once '../../Classes/PHPWord.php';
// Init
error_reporting(E_ALL);
define('EOL', (PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
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;

View File

@ -0,0 +1,42 @@
<?php
/**
* Image creation
*/
// Init
error_reporting(E_ALL);
define('EOL', (PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
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;

View File

@ -1,10 +1,18 @@
<?php
require_once '../../Classes/PHPWord.php';
/**
* List item sample
*/
// New Word Document
// Init
error_reporting(E_ALL);
define('EOL', (PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
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;

View File

@ -0,0 +1,40 @@
<?php
/**
* Link sample
*/
// Init
error_reporting(E_ALL);
define('EOL', (PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
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;

View File

@ -0,0 +1,35 @@
<?php
/**
* Object sample
*/
// Init
error_reporting(E_ALL);
define('EOL', (PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
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;

View File

@ -1,10 +1,18 @@
<?php
require_once '../../Classes/PHPWord.php';
/**
* Generic template for creating PHPWord samples
*/
// New Word Document
// Init
error_reporting(E_ALL);
define('EOL', (PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
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;

View File

@ -0,0 +1,36 @@
<?php
/**
* Generic template for creating PHPWord samples
*/
// Init
error_reporting(E_ALL);
define('EOL', (PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
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;

View File

@ -1,52 +0,0 @@
<?php
require_once '../../Classes/PHPWord.php';
// New Word Document
$PHPWord = new PHPWord();
// New portrait section
$section = $PHPWord->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');

View File

@ -1,25 +0,0 @@
<?php
require_once '../../Classes/PHPWord.php';
// New Word Document
$PHPWord = new PHPWord();
// New portrait section
$section = $PHPWord->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');

View File

@ -1,23 +0,0 @@
<?php
require_once '../../Classes/PHPWord.php';
// New Word Document
$PHPWord = new PHPWord();
// New portrait section
$section = $PHPWord->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');

View File

@ -1,23 +0,0 @@
<?php
require_once '../../Classes/PHPWord.php';
// New Word Document
$PHPWord = new PHPWord();
// New portrait section
$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');
// Save File
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007');
$objWriter->save('Link.docx');

View File

@ -1,19 +0,0 @@
<?php
require_once '../../Classes/PHPWord.php';
// New Word Document
$PHPWord = new PHPWord();
// New portrait section
$section = $PHPWord->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');

View File

@ -1,25 +0,0 @@
<?php
require_once '../../Classes/PHPWord.php';
// New Word Document
$PHPWord = new PHPWord();
// New portrait section
$section = $PHPWord->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');

View File

@ -1,22 +0,0 @@
<?php
require_once '../../Classes/PHPWord.php';
$PHPWord = new PHPWord();
$document = $PHPWord->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');

View File

@ -1,31 +0,0 @@
<?php
require_once '../../Classes/PHPWord.php';
// New Word Document
$PHPWord = new PHPWord();
// New portrait section
$section = $PHPWord->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');

View File

@ -1,20 +0,0 @@
<?php
require_once '../../Classes/PHPWord.php';
// New Word Document
$PHPWord = new PHPWord();
// New portrait section
$section = $PHPWord->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');

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

View File

Before

Width:  |  Height:  |  Size: 37 KiB

After

Width:  |  Height:  |  Size: 37 KiB

View File

Before

Width:  |  Height:  |  Size: 24 KiB

After

Width:  |  Height:  |  Size: 24 KiB