Skip to content

Commit a1d5f82

Browse files
committed
Initial Commit
1 parent 8b80028 commit a1d5f82

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+10271
-0
lines changed

src/Examples/AdvancedTable.php

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
require_once '../PHPWord.php';
3+
4+
// New Word Document
5+
$PHPWord = new PHPWord();
6+
7+
// New portrait section
8+
$section = $PHPWord->createSection();
9+
10+
// Define table style arrays
11+
$styleTable = array('borderSize'=>6, 'borderColor'=>'006699', 'cellMargin'=>80);
12+
$styleFirstRow = array('borderBottomSize'=>18, 'borderBottomColor'=>'0000FF', 'bgColor'=>'66BBFF');
13+
14+
// Define cell style arrays
15+
$styleCell = array('valign'=>'center');
16+
$styleCellBTLR = array('valign'=>'center', 'textDirection'=>PHPWord_Style_Cell::TEXT_DIR_BTLR);
17+
18+
// Define font style for first row
19+
$fontStyle = array('bold'=>true, 'align'=>'center');
20+
21+
// Add table style
22+
$PHPWord->addTableStyle('myOwnTableStyle', $styleTable, $styleFirstRow);
23+
24+
// Add table
25+
$table = $section->addTable('myOwnTableStyle');
26+
27+
// Add row
28+
$table->addRow(900);
29+
30+
// Add cells
31+
$table->addCell(2000, $styleCell)->addText('Row 1', $fontStyle);
32+
$table->addCell(2000, $styleCell)->addText('Row 2', $fontStyle);
33+
$table->addCell(2000, $styleCell)->addText('Row 3', $fontStyle);
34+
$table->addCell(2000, $styleCell)->addText('Row 4', $fontStyle);
35+
$table->addCell(500, $styleCellBTLR)->addText('Row 5', $fontStyle);
36+
37+
// Add more rows / cells
38+
for($i = 1; $i <= 10; $i++) {
39+
$table->addRow();
40+
$table->addCell(2000)->addText("Cell $i");
41+
$table->addCell(2000)->addText("Cell $i");
42+
$table->addCell(2000)->addText("Cell $i");
43+
$table->addCell(2000)->addText("Cell $i");
44+
45+
$text = ($i % 2 == 0) ? 'X' : '';
46+
$table->addCell(500)->addText($text);
47+
}
48+
49+
50+
// Save File
51+
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007');
52+
$objWriter->save('AdvancedTable.docx');
53+
?>

src/Examples/BasicTable.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
require_once '../PHPWord.php';
3+
4+
// New Word Document
5+
$PHPWord = new PHPWord();
6+
7+
// New portrait section
8+
$section = $PHPWord->createSection();
9+
10+
// Add table
11+
$table = $section->addTable();
12+
13+
for($r = 1; $r <= 10; $r++) { // Loop through rows
14+
// Add row
15+
$table->addRow();
16+
17+
for($c = 1; $c <= 5; $c++) { // Loop through cells
18+
// Add Cell
19+
$table->addCell(1750)->addText("Row $r, Cell $c");
20+
}
21+
}
22+
23+
// Save File
24+
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007');
25+
$objWriter->save('BasicTable.docx');
26+
?>

src/Examples/HeaderFooter.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
require_once '../PHPWord.php';
3+
4+
// New Word Document
5+
$PHPWord = new PHPWord();
6+
7+
// New portrait section
8+
$section = $PHPWord->createSection();
9+
10+
// Add header
11+
$header = $section->createHeader();
12+
$table = $header->addTable();
13+
$table->addRow();
14+
$table->addCell(4500)->addText('This is the header.');
15+
$table->addCell(4500)->addImage('_earth.jpg', array('width'=>50, 'height'=>50, 'align'=>'right'));
16+
17+
// Add footer
18+
$footer = $section->createFooter();
19+
$footer->addPreserveText('Page {PAGE} of {NUMPAGES}.', array('align'=>'center'));
20+
21+
// Write some text
22+
$section->addTextBreak();
23+
$section->addText('Some text...');
24+
25+
// Save File
26+
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007');
27+
$objWriter->save('HeaderFooter.docx');
28+
?>

src/Examples/Image.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
require_once '../PHPWord.php';
3+
4+
// New Word Document
5+
$PHPWord = new PHPWord();
6+
7+
// New portrait section
8+
$section = $PHPWord->createSection();
9+
10+
// Add image elements
11+
$section->addImage('_mars.jpg');
12+
$section->addTextBreak(2);
13+
14+
$section->addImage('_earth.JPG', array('width'=>210, 'height'=>210, 'align'=>'center'));
15+
$section->addTextBreak(2);
16+
17+
$section->addImage('_mars.jpg', array('width'=>100, 'height'=>100, 'align'=>'right'));
18+
19+
20+
21+
// Save File
22+
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007');
23+
$objWriter->save('Image.docx');
24+
?>

src/Examples/Link.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
require_once '../PHPWord.php';
3+
4+
// New Word Document
5+
$PHPWord = new PHPWord();
6+
7+
// New portrait section
8+
$section = $PHPWord->createSection();
9+
10+
// Add hyperlink elements
11+
$section->addLink('http://www.google.com', 'Best search engine', array('color'=>'0000FF', 'underline'=>PHPWord_Style_Font::UNDERLINE_SINGLE));
12+
$section->addTextBreak(2);
13+
14+
$PHPWord->addLinkStyle('myOwnLinkStyle', array('bold'=>true, 'color'=>'808000'));
15+
$section->addLink('http://www.bing.com', null, 'myOwnLinkStyle');
16+
$section->addLink('http://www.yahoo.com', null, 'myOwnLinkStyle');
17+
18+
19+
20+
21+
// Save File
22+
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007');
23+
$objWriter->save('Link.docx');
24+
?>

src/Examples/ListItem.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
require_once '../PHPWord.php';
3+
4+
// New Word Document
5+
$PHPWord = new PHPWord();
6+
7+
// New portrait section
8+
$section = $PHPWord->createSection();
9+
10+
// Add listitem elements
11+
$section->addListItem('List Item 1', 0);
12+
$section->addListItem('List Item 2', 0);
13+
$section->addListItem('List Item 3', 0);
14+
$section->addTextBreak(2);
15+
16+
// Add listitem elements
17+
$section->addListItem('List Item 1', 0);
18+
$section->addListItem('List Item 1.1', 1);
19+
$section->addListItem('List Item 1.2', 1);
20+
$section->addListItem('List Item 1.3 (styled)', 1, array('bold'=>true));
21+
$section->addListItem('List Item 1.3.1', 2);
22+
$section->addListItem('List Item 1.3.2', 2);
23+
$section->addTextBreak(2);
24+
25+
// Add listitem elements
26+
$listStyle = array('listType'=>PHPWord_Style_ListItem::TYPE_NUMBER);
27+
$section->addListItem('List Item 1', 0, null, $listStyle);
28+
$section->addListItem('List Item 2', 0, null, $listStyle);
29+
$section->addListItem('List Item 3', 0, null, $listStyle);
30+
$section->addTextBreak(2);
31+
32+
// Add listitem elements
33+
$PHPWord->addFontStyle('myOwnStyle', array('color'=>'FF0000'));
34+
$PHPWord->addParagraphStyle('P-Style', array('spaceAfter'=>95));
35+
$listStyle = array('listType'=>PHPWord_Style_ListItem::TYPE_NUMBER_NESTED);
36+
$section->addListItem('List Item 1', 0, 'myOwnStyle', $listStyle, 'P-Style');
37+
$section->addListItem('List Item 2', 0, 'myOwnStyle', $listStyle, 'P-Style');
38+
$section->addListItem('List Item 3', 1, 'myOwnStyle', $listStyle, 'P-Style');
39+
$section->addListItem('List Item 4', 1, 'myOwnStyle', $listStyle, 'P-Style');
40+
$section->addListItem('List Item 5', 2, 'myOwnStyle', $listStyle, 'P-Style');
41+
$section->addListItem('List Item 6', 1, 'myOwnStyle', $listStyle, 'P-Style');
42+
$section->addListItem('List Item 7', 0, 'myOwnStyle', $listStyle, 'P-Style');
43+
44+
// Save File
45+
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007');
46+
$objWriter->save('ListItem.docx');
47+
?>

src/Examples/Object.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
require_once '../PHPWord.php';
3+
4+
// New Word Document
5+
$PHPWord = new PHPWord();
6+
7+
// New portrait section
8+
$section = $PHPWord->createSection();
9+
10+
// Add text elements
11+
$section->addText('You can open this OLE object by double clicking on the icon:');
12+
$section->addTextBreak(2);
13+
14+
// Add object
15+
$section->addObject('_sheet.xls');
16+
17+
// Save File
18+
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007');
19+
$objWriter->save('Object.docx');
20+
?>

src/Examples/Section.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
require_once '../PHPWord.php';
3+
4+
// New Word Document
5+
$PHPWord = new PHPWord();
6+
7+
// New portrait section
8+
$section = $PHPWord->createSection(array('borderColor'=>'00FF00', 'borderSize'=>12));
9+
$section->addText('I am placed on a default section.');
10+
11+
// New landscape section
12+
$section = $PHPWord->createSection(array('orientation'=>'landscape'));
13+
$section->addText('I am placed on a landscape section. Every page starting from this section will be landscape style.');
14+
$section->addPageBreak();
15+
$section->addPageBreak();
16+
17+
// New portrait section
18+
$section = $PHPWord->createSection(array('marginLeft'=>600, 'marginRight'=>600, 'marginTop'=>600, 'marginBottom'=>600));
19+
$section->addText('This section uses other margins.');
20+
21+
22+
23+
// Save File
24+
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007');
25+
$objWriter->save('Section.docx');
26+
?>

src/Examples/Template.docx

14.5 KB
Binary file not shown.

src/Examples/Template.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
require_once '../PHPWord.php';
3+
4+
$PHPWord = new PHPWord();
5+
6+
$document = $PHPWord->loadTemplate('Template.docx');
7+
8+
$document->setValue('Value1', 'Sun');
9+
$document->setValue('Value2', 'Mercury');
10+
$document->setValue('Value3', 'Venus');
11+
$document->setValue('Value4', 'Earth');
12+
$document->setValue('Value5', 'Mars');
13+
$document->setValue('Value6', 'Jupiter');
14+
$document->setValue('Value7', 'Saturn');
15+
$document->setValue('Value8', 'Uranus');
16+
$document->setValue('Value9', 'Neptun');
17+
$document->setValue('Value10', 'Pluto');
18+
19+
$document->setValue('weekday', date('l'));
20+
$document->setValue('time', date('H:i'));
21+
22+
$document->save('Solarsystem.docx');
23+
?>

0 commit comments

Comments
 (0)