./tests/PhpWord
@@ -22,7 +21,7 @@
-
+
\ No newline at end of file
diff --git a/samples/Sample_01_SimpleText.php b/samples/Sample_01_SimpleText.php
index 5a3393b3..8af44d20 100644
--- a/samples/Sample_01_SimpleText.php
+++ b/samples/Sample_01_SimpleText.php
@@ -1,6 +1,5 @@
setValue('userPhone#3', '+1 428 889 775');
echo date('H:i:s'), ' Saving the result document...', EOL;
$templateProcessor->saveAs('results/Sample_07_TemplateCloneRow.docx');
-echo getEndingNotes(array('Word2007' => 'docx'));
+echo getEndingNotes(array('Word2007' => 'docx'), 'results/Sample_07_TemplateCloneRow.docx');
if (!CLI) {
include_once 'Sample_Footer.php';
}
diff --git a/samples/Sample_09_Tables.php b/samples/Sample_09_Tables.php
index c4be7c9e..32d89573 100644
--- a/samples/Sample_09_Tables.php
+++ b/samples/Sample_09_Tables.php
@@ -1,4 +1,7 @@
addTextBreak(1);
$section->addText('Fancy table', $header);
$fancyTableStyleName = 'Fancy Table';
-$fancyTableStyle = array('borderSize' => 6, 'borderColor' => '006699', 'cellMargin' => 80, 'alignment' => \PhpOffice\PhpWord\SimpleType\JcTable::CENTER);
+$fancyTableStyle = array('borderSize' => 6, 'borderColor' => '006699', 'cellMargin' => 80, 'alignment' => \PhpOffice\PhpWord\SimpleType\JcTable::CENTER, 'cellSpacing' => 50);
$fancyTableFirstRowStyle = array('borderBottomSize' => 18, 'borderBottomColor' => '0000FF', 'bgColor' => '66BBFF');
$fancyTableCellStyle = array('valign' => 'center');
$fancyTableCellBtlrStyle = array('valign' => 'center', 'textDirection' => \PhpOffice\PhpWord\Style\Cell::TEXT_DIR_BTLR);
@@ -113,20 +116,20 @@ $phpWord->addTableStyle('Colspan Rowspan', $styleTable);
$table = $section->addTable('Colspan Rowspan');
$row = $table->addRow();
-
-$row->addCell(null, array('vMerge' => 'restart'))->addText('A');
-$row->addCell(null, array('gridSpan' => 2, 'vMerge' => 'restart'))->addText('B');
-$row->addCell()->addText('1');
+$row->addCell(1000, array('vMerge' => 'restart'))->addText('A');
+$row->addCell(1000, array('gridSpan' => 2, 'vMerge' => 'restart'))->addText('B');
+$row->addCell(1000)->addText('1');
$row = $table->addRow();
-$row->addCell(null, array('vMerge' => 'continue'));
-$row->addCell(null, array('vMerge' => 'continue', 'gridSpan' => 2));
-$row->addCell()->addText('2');
+$row->addCell(1000, array('vMerge' => 'continue'));
+$row->addCell(1000, array('vMerge' => 'continue', 'gridSpan' => 2));
+$row->addCell(1000)->addText('2');
+
$row = $table->addRow();
-$row->addCell(null, array('vMerge' => 'continue'));
-$row->addCell()->addText('C');
-$row->addCell()->addText('D');
-$row->addCell()->addText('3');
+$row->addCell(1000, array('vMerge' => 'continue'));
+$row->addCell(1000)->addText('C');
+$row->addCell(1000)->addText('D');
+$row->addCell(1000)->addText('3');
// 5. Nested table
@@ -139,6 +142,15 @@ $cell->addText('This cell contains nested table.');
$innerCell = $cell->addTable(array('alignment' => \PhpOffice\PhpWord\SimpleType\JcTable::CENTER))->addRow()->addCell();
$innerCell->addText('Inside nested table');
+// 6. Table with floating position
+
+$section->addTextBreak(2);
+$section->addText('Table with floating positioning.', $header);
+
+$table = $section->addTable(array('borderSize' => 6, 'borderColor' => '999999', 'position' => array('vertAnchor' => TablePosition::VANCHOR_TEXT, 'bottomFromText' => Converter::cmToTwip(1))));
+$cell = $table->addRow()->addCell();
+$cell->addText('This is a single cell.');
+
// Save file
echo write($phpWord, basename(__FILE__, '.php'), $writers);
if (!CLI) {
diff --git a/samples/Sample_13_Images.php b/samples/Sample_13_Images.php
index 6c7033b0..f7be3be9 100644
--- a/samples/Sample_13_Images.php
+++ b/samples/Sample_13_Images.php
@@ -1,4 +1,7 @@
addSection();
$section->addText('Local image without any styles:');
$section->addImage('resources/_mars.jpg');
-$section->addTextBreak(2);
+printSeparator($section);
$section->addText('Local image with styles:');
$section->addImage('resources/_earth.jpg', array('width' => 210, 'height' => 210, 'alignment' => \PhpOffice\PhpWord\SimpleType\Jc::CENTER));
-$section->addTextBreak(2);
// Remote image
+printSeparator($section);
$source = 'http://php.net/images/logos/php-med-trans-light.gif';
$section->addText("Remote image from: {$source}");
$section->addImage($source);
// Image from string
+printSeparator($section);
$source = 'resources/_mars.jpg';
$fileContent = file_get_contents($source);
$section->addText('Image from string');
$section->addImage($fileContent);
//Wrapping style
-$text = str_repeat('Hello World! ', 15);
+printSeparator($section);
+$text = str_repeat('Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. ', 2);
$wrappingStyles = array('inline', 'behind', 'infront', 'square', 'tight');
foreach ($wrappingStyles as $wrappingStyle) {
- $section->addTextBreak(5);
$section->addText("Wrapping style {$wrappingStyle}");
$section->addImage(
'resources/_earth.jpg',
array(
- 'positioning' => 'relative',
- 'marginTop' => -1,
- 'marginLeft' => 1,
- 'width' => 80,
- 'height' => 80,
- 'wrappingStyle' => $wrappingStyle,
+ 'positioning' => 'relative',
+ 'marginTop' => -1,
+ 'marginLeft' => 1,
+ 'width' => 80,
+ 'height' => 80,
+ 'wrappingStyle' => $wrappingStyle,
+ 'wrapDistanceRight' => Converter::cmToPoint(1),
+ 'wrapDistanceBottom' => Converter::cmToPoint(1),
)
);
$section->addText($text);
+ printSeparator($section);
}
//Absolute positioning
-$section->addTextBreak(3);
$section->addText('Absolute positioning: see top right corner of page');
$section->addImage(
'resources/_mars.jpg',
@@ -64,7 +70,7 @@ $section->addImage(
);
//Relative positioning
-$section->addTextBreak(3);
+printSeparator($section);
$section->addText('Relative positioning: Horizontal position center relative to column,');
$section->addText('Vertical position top relative to line');
$section->addImage(
@@ -80,6 +86,14 @@ $section->addImage(
)
);
+function printSeparator(Section $section)
+{
+ $section->addTextBreak();
+ $lineStyle = array('weight' => 0.2, 'width' => 150, 'height' => 0, 'align' => 'center');
+ $section->addLine($lineStyle);
+ $section->addTextBreak(2);
+}
+
// Save file
echo write($phpWord, basename(__FILE__, '.php'), $writers);
if (!CLI) {
diff --git a/samples/Sample_14_ListItem.php b/samples/Sample_14_ListItem.php
index 689ac3d3..774fd284 100644
--- a/samples/Sample_14_ListItem.php
+++ b/samples/Sample_14_ListItem.php
@@ -67,6 +67,8 @@ $listItemRun->addText(' in bold', array('bold' => true));
$listItemRun = $section->addListItemRun();
$listItemRun->addText('List item 2');
$listItemRun->addText(' in italic', array('italic' => true));
+$footnote = $listItemRun->addFootnote();
+$footnote->addText('this is a footnote on a list item');
$listItemRun = $section->addListItemRun();
$listItemRun->addText('List item 3');
$listItemRun->addText(' underlined', array('underline' => 'dash'));
diff --git a/samples/Sample_16_Object.php b/samples/Sample_16_Object.php
index 8b05b9e8..c4db7f61 100644
--- a/samples/Sample_16_Object.php
+++ b/samples/Sample_16_Object.php
@@ -9,7 +9,7 @@ $phpWord = new \PhpOffice\PhpWord\PhpWord();
$section = $phpWord->addSection();
$section->addText('You can open this OLE object by double clicking on the icon:');
$section->addTextBreak(2);
-$section->addObject('resources/_sheet.xls');
+$section->addOLEObject('resources/_sheet.xls');
// Save file
echo write($phpWord, basename(__FILE__, '.php'), $writers);
diff --git a/samples/Sample_17_TitleTOC.php b/samples/Sample_17_TitleTOC.php
index f99b73ea..86e8e28c 100644
--- a/samples/Sample_17_TitleTOC.php
+++ b/samples/Sample_17_TitleTOC.php
@@ -12,13 +12,14 @@ $section = $phpWord->addSection();
// Define styles
$fontStyle12 = array('spaceAfter' => 60, 'size' => 12);
$fontStyle10 = array('size' => 10);
+$phpWord->addTitleStyle(null, array('size' => 22, 'bold' => true));
$phpWord->addTitleStyle(1, array('size' => 20, 'color' => '333333', 'bold' => true));
$phpWord->addTitleStyle(2, array('size' => 16, 'color' => '666666'));
$phpWord->addTitleStyle(3, array('size' => 14, 'italic' => true));
$phpWord->addTitleStyle(4, array('size' => 12));
// Add text elements
-$section->addText('Table of contents 1');
+$section->addTitle('Table of contents 1', 0);
$section->addTextBreak(2);
// Add TOC #1
diff --git a/samples/Sample_23_TemplateBlock.php b/samples/Sample_23_TemplateBlock.php
index 2b7e9f68..ed986618 100644
--- a/samples/Sample_23_TemplateBlock.php
+++ b/samples/Sample_23_TemplateBlock.php
@@ -14,7 +14,7 @@ $templateProcessor->deleteBlock('DELETEME');
echo date('H:i:s'), ' Saving the result document...', EOL;
$templateProcessor->saveAs('results/Sample_23_TemplateBlock.docx');
-echo getEndingNotes(array('Word2007' => 'docx'));
+echo getEndingNotes(array('Word2007' => 'docx'), 'results/Sample_23_TemplateBlock.docx');
if (!CLI) {
include_once 'Sample_Footer.php';
}
diff --git a/samples/Sample_26_Html.php b/samples/Sample_26_Html.php
index 69d9d131..e1823c43 100644
--- a/samples/Sample_26_Html.php
+++ b/samples/Sample_26_Html.php
@@ -4,17 +4,25 @@ include_once 'Sample_Header.php';
// New Word Document
echo date('H:i:s') , ' Create new PhpWord object' , EOL;
$phpWord = new \PhpOffice\PhpWord\PhpWord();
+$phpWord->addParagraphStyle('Heading2', array('alignment' => 'center'));
$section = $phpWord->addSection();
$html = 'Adding element via HTML
';
-$html .= 'Some well formed HTML snippet needs to be used
';
+$html .= 'Some well-formed HTML snippet needs to be used
';
$html .= 'With for example some1 inline formatting1
';
-$html .= 'A link to Read the docs
';
+$html .= 'A link to Read the docs
';
+
+$html .= 'היי, זה פסקה מימין לשמאל
';
$html .= 'Unordered (bulleted) list:
';
$html .= '';
+$html .= '1.5 line height with first line text indent:
';
+$html .= 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
';
+
+$html .= 'centered title
';
+
$html .= 'Ordered (numbered) list:
';
$html .= '
List 1 item 1
@@ -29,10 +37,12 @@ $html .= '
- List 2 item 1
- List 2 item 2
-
- - sub list 1
- - sub list 2
-
+ -
+
+ - sub list 1
+ - sub list 2
+
+
- List 2 item 3
- sub list 1, restarts with a
@@ -65,10 +75,20 @@ $html .= '
| 1 | 2 |
- | 4 | 5 | 6 |
+ | This is bold text | | 6 |
';
+$html .= 'Table inside another table:
';
+$html .= '
+ |
+
+ |
+ | Cell in parent table |
+
';
+
\PhpOffice\PhpWord\Shared\Html::addHtml($section, $html, false, false);
// Save file
diff --git a/samples/Sample_27_Field.php b/samples/Sample_27_Field.php
index ec9dbe25..4e7a5b22 100644
--- a/samples/Sample_27_Field.php
+++ b/samples/Sample_27_Field.php
@@ -6,20 +6,26 @@ include_once 'Sample_Header.php';
// New Word document
echo date('H:i:s'), ' Create new PhpWord object', EOL;
$phpWord = new \PhpOffice\PhpWord\PhpWord();
+PhpOffice\PhpWord\Style::addTitleStyle(1, array('size' => 14));
// New section
$section = $phpWord->addSection();
+$section->addTitle('This page demos fields');
// Add Field elements
// See Element/Field.php for all options
$section->addText('Date field:');
$section->addField('DATE', array('dateformat' => 'dddd d MMMM yyyy H:mm:ss'), array('PreserveFormat'));
+$section->addText('Style Ref field:');
+$section->addField('STYLEREF', array('StyleIdentifier' => 'Heading 1'));
+
$section->addText('Page field:');
$section->addField('PAGE', array('format' => 'Arabic'));
$section->addText('Number of pages field:');
$section->addField('NUMPAGES', array('numformat' => '0,00', 'format' => 'Arabic'), array('PreserveFormat'));
+$section->addTextBreak();
$textrun = $section->addTextRun();
$textrun->addText('An index field is ');
@@ -43,6 +49,19 @@ $textrun = $section->addTextRun(array('alignment' => \PhpOffice\PhpWord\SimpleTy
$textrun->addText('This is the date of lunar calendar ');
$textrun->addField('DATE', array('dateformat' => 'd-M-yyyy H:mm:ss'), array('PreserveFormat', 'LunarCalendar'));
$textrun->addText(' written in a textrun.');
+$section->addTextBreak();
+
+$macroText = new TextRun();
+$macroText->addText('Double click', array('bold' => true));
+$macroText->addText(' to ');
+$macroText->addText('zoom to 100%', array('italic' => true));
+
+$section->addText('A macro button with styled text:');
+$section->addField('MACROBUTTON', array('macroname' => 'Zoom100'), array(), $macroText);
+$section->addTextBreak();
+
+$section->addText('A macro button with simple text:');
+$section->addField('MACROBUTTON', array('macroname' => 'Zoom100'), array(), 'double click to zoom');
// Save file
echo write($phpWord, basename(__FILE__, '.php'), $writers);
diff --git a/samples/Sample_32_Chart.php b/samples/Sample_32_Chart.php
index 2c6458ca..c24a6f8e 100644
--- a/samples/Sample_32_Chart.php
+++ b/samples/Sample_32_Chart.php
@@ -16,18 +16,23 @@ $section = $phpWord->addSection();
$section->addTitle('2D charts', 1);
$section = $phpWord->addSection(array('colsNum' => 2, 'breakType' => 'continuous'));
-$chartTypes = array('pie', 'doughnut', 'bar', 'column', 'line', 'area', 'scatter', 'radar');
-$twoSeries = array('bar', 'column', 'line', 'area', 'scatter', 'radar');
+$chartTypes = array('pie', 'doughnut', 'bar', 'column', 'line', 'area', 'scatter', 'radar', 'stacked_bar', 'percent_stacked_bar', 'stacked_column', 'percent_stacked_column');
+$twoSeries = array('bar', 'column', 'line', 'area', 'scatter', 'radar', 'stacked_bar', 'percent_stacked_bar', 'stacked_column', 'percent_stacked_column');
$threeSeries = array('bar', 'line');
$categories = array('A', 'B', 'C', 'D', 'E');
$series1 = array(1, 3, 2, 5, 4);
$series2 = array(3, 1, 7, 2, 6);
$series3 = array(8, 3, 2, 5, 4);
+$showGridLines = false;
+$showAxisLabels = false;
foreach ($chartTypes as $chartType) {
$section->addTitle(ucfirst($chartType), 2);
$chart = $section->addChart($chartType, $categories, $series1);
$chart->getStyle()->setWidth(Converter::inchToEmu(2.5))->setHeight(Converter::inchToEmu(2));
+ $chart->getStyle()->setShowGridX($showGridLines);
+ $chart->getStyle()->setShowGridY($showGridLines);
+ $chart->getStyle()->setShowAxisLabels($showAxisLabels);
if (in_array($chartType, $twoSeries)) {
$chart->addSeries($categories, $series2);
}
@@ -44,7 +49,14 @@ $section = $phpWord->addSection(array('colsNum' => 2, 'breakType' => 'continuous
$chartTypes = array('pie', 'bar', 'column', 'line', 'area');
$multiSeries = array('bar', 'column', 'line', 'area');
-$style = array('width' => Converter::cmToEmu(5), 'height' => Converter::cmToEmu(4), '3d' => true);
+$style = array(
+ 'width' => Converter::cmToEmu(5),
+ 'height' => Converter::cmToEmu(4),
+ '3d' => true,
+ 'showAxisLabels' => $showAxisLabels,
+ 'showGridX' => $showGridLines,
+ 'showGridY' => $showGridLines,
+);
foreach ($chartTypes as $chartType) {
$section->addTitle(ucfirst($chartType), 2);
$chart = $section->addChart($chartType, $categories, $series1, $style);
diff --git a/samples/Sample_39_TrackChanges.php b/samples/Sample_39_TrackChanges.php
new file mode 100644
index 00000000..e6a30668
--- /dev/null
+++ b/samples/Sample_39_TrackChanges.php
@@ -0,0 +1,29 @@
+addSection();
+$textRun = $section->addTextRun();
+
+$text = $textRun->addText('Hello World! Time to ');
+
+$text = $textRun->addText('wake ', array('bold' => true));
+$text->setChangeInfo(TrackChange::INSERTED, 'Fred', time() - 1800);
+
+$text = $textRun->addText('up');
+$text->setTrackChange(new TrackChange(TrackChange::INSERTED, 'Fred'));
+
+$text = $textRun->addText('go to sleep');
+$text->setChangeInfo(TrackChange::DELETED, 'Barney', new \DateTime('@' . (time() - 3600)));
+
+// Save file
+echo write($phpWord, basename(__FILE__, '.php'), $writers);
+if (!CLI) {
+ include_once 'Sample_Footer.php';
+}
diff --git a/samples/Sample_Header.php b/samples/Sample_Header.php
index ac51f983..f0fc6266 100644
--- a/samples/Sample_Header.php
+++ b/samples/Sample_Header.php
@@ -83,7 +83,7 @@ function write($phpWord, $filename, $writers)
$result .= EOL;
}
- $result .= getEndingNotes($writers);
+ $result .= getEndingNotes($writers, $filename);
return $result;
}
@@ -92,10 +92,10 @@ function write($phpWord, $filename, $writers)
* Get ending notes
*
* @param array $writers
- *
+ * @param mixed $filename
* @return string
*/
-function getEndingNotes($writers)
+function getEndingNotes($writers, $filename)
{
$result = '';
diff --git a/samples/resources/Sample_11_ReadWord2007.docx b/samples/resources/Sample_11_ReadWord2007.docx
index c9a50f48..406cf1e1 100644
Binary files a/samples/resources/Sample_11_ReadWord2007.docx and b/samples/resources/Sample_11_ReadWord2007.docx differ
diff --git a/samples/resources/Sample_24_ReadODText.odt b/samples/resources/Sample_24_ReadODText.odt
index d37c4e66..59ac16da 100644
Binary files a/samples/resources/Sample_24_ReadODText.odt and b/samples/resources/Sample_24_ReadODText.odt differ
diff --git a/samples/resources/Sample_30_ReadHTML.html b/samples/resources/Sample_30_ReadHTML.html
index 5593298b..b3d2fad2 100644
--- a/samples/resources/Sample_30_ReadHTML.html
+++ b/samples/resources/Sample_30_ReadHTML.html
@@ -11,5 +11,15 @@
Ordered (numbered) list:
- Item 1
- Item 2
+
+Double height
+
+Includes images
+
+
+
+
+
+