From: Alan Knowles Date: Tue, 18 Dec 2012 09:00:25 +0000 (+0800) Subject: add exmpales X-Git-Url: http://git.roojs.org/?p=pear-examples;a=commitdiff_plain;h=fb2a964796f047fc9d388a46f5888b1a7acb7e35 add exmpales --- diff --git a/Document_Word_Writer/Examples/AdvancedTable.php b/Document_Word_Writer/Examples/AdvancedTable.php new file mode 100644 index 0000000..6b1f160 --- /dev/null +++ b/Document_Word_Writer/Examples/AdvancedTable.php @@ -0,0 +1,56 @@ +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'=>Document_Word_Writer_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 +require_once __DIR__ . '/../Writer/IOFactory.php'; +$objWriter = Document_Word_Writer_IOFactory::createWriter($PHPWord, 'Word2007'); +$objWriter->save('/tmp/AdvancedTable.docx'); +?> \ No newline at end of file diff --git a/Document_Word_Writer/Examples/BasicTable.php b/Document_Word_Writer/Examples/BasicTable.php new file mode 100644 index 0000000..98ed9c7 --- /dev/null +++ b/Document_Word_Writer/Examples/BasicTable.php @@ -0,0 +1,52 @@ +createSection(); + +// Add table +$table = $section->addTable(); + +$cellStyle = array('bgColor'=>'C0C0C0'); + +$table = $section->addTable(); +$table->addRow(1000); +$table->addCell(2000, $cellStyle)->addText('Cell 1'); +$table->addCell(2000, $cellStyle)->addText('Cell 2'); +$table->addCell(2000, $cellStyle)->addText('Cell 3'); +$table->addRow(); +$table->addCell(2000)->addText('Cell 4'); +$table->addCell(2000)->addText('Cell 5'); +$table->addCell(2000)->addText('Cell 6'); + +// Save File +require_once __DIR__ . '/../Writer/IOFactory.php'; +$objWriter = Document_Word_Writer_IOFactory::createWriter($PHPWord, 'Word2007'); +$objWriter->save('/tmp/BasicTable.docx'); + +// Download the file for testing +if($_SERVER['SERVER_NAME'] == 'localhost') +{ + exit; +} +$file = '/tmp/BasicTable.docx'; +if (file_exists($file)) { + echo 'Prepare for download!!'; + header('Content-Description: File Transfer'); + header('Content-Type: application/octet-stream'); + header('Content-Disposition: attachment; filename='.basename($file)); + header('Content-Transfer-Encoding: binary'); + header('Expires: 0'); + header('Cache-Control: must-revalidate'); + header('Pragma: public'); + header('Content-Length: ' . filesize($file)); + ob_clean(); + flush(); + readfile($file); + exit; +} + +?> diff --git a/Document_Word_Writer/Examples/BasicTable.php~ b/Document_Word_Writer/Examples/BasicTable.php~ new file mode 100644 index 0000000..61141e8 --- /dev/null +++ b/Document_Word_Writer/Examples/BasicTable.php~ @@ -0,0 +1,28 @@ +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 +require_once 'Document/Word/Writer/IOFactory.php'; +$objWriter = Document_Word_Writer_IOFactory::createWriter($PHPWord, 'Word2007'); +$objWriter->save('BasicTable.docx'); +?> diff --git a/Document_Word_Writer/Examples/HeaderFooter.php b/Document_Word_Writer/Examples/HeaderFooter.php new file mode 100644 index 0000000..cfe9491 --- /dev/null +++ b/Document_Word_Writer/Examples/HeaderFooter.php @@ -0,0 +1,46 @@ +createSection(); + +// Add header +$header = $section->createHeader(); +$table = $header->addTable(); +$table->addRow(); +$table->addCell(3000)->addText('This is the header.', array('align'=>'right') , array('align'=>'right')); +$table->addCell(5000)->addImage('_earth.JPG', array('width'=>50, 'height'=>50, 'align'=>'right')); + +// Add footer +$footer = $section->createFooter(); +$footer->addPreserveText('Page {PAGE} of {NUMPAGES}.', array('align'=>'right')); + +// Write some text +$section->addTextBreak(); +$section->addText('Some text...'); + +// Save File +require_once __DIR__ . '/../Writer/IOFactory.php'; +$objWriter = Document_Word_Writer_IOFactory::createWriter($PHPWord, 'Word2007'); +$objWriter->save('/tmp/HeaderFooter.docx'); +$fn = '/tmp/HeaderFooter.docx'; +if (file_exists($fn)) { + echo 'Prepare for download!!'; + header('Content-Description: File Transfer'); + header('Content-Type: application/octet-stream'); + header('Content-Disposition: attachment; filename='.basename($fn)); + header('Content-Transfer-Encoding: binary'); + header('Expires: 0'); + header('Cache-Control: must-revalidate'); + header('Pragma: public'); + header('Content-Length: ' . filesize($fn)); + ob_clean(); + flush(); + readfile($fn); + exit; +} +?> \ No newline at end of file diff --git a/Document_Word_Writer/Examples/Image.php b/Document_Word_Writer/Examples/Image.php new file mode 100644 index 0000000..7fc3fcc --- /dev/null +++ b/Document_Word_Writer/Examples/Image.php @@ -0,0 +1,52 @@ +createSection(); + +// Add image elements +//$section->addImage('_mars.jpg'); +//$section->addTextBreak(2); +$section->addText('Below is earth image!'); +$section->addTextBreak(2); +$section->addImage('_earth.JPG', array('width'=>500, 'height'=>500)); +$section->addTextBreak(2); +$section->addText('Above is earth image!'); +//$section->addImage('_mars.jpg'); + +// add in /tmp/67219.0.jpg +//$rid = $section->addImageDefered('_earth.JPG', array('width'=>210, 'height'=>210, 'align'=>'center')); +// store map [67219.0] = $rid + +// when get image - > lookup map [67219.0] for rid +//$section->addImageToCollection($rid, '_earth.JPG'); // 67219.0.jpg/:;: +$fn = '/tmp/Image.docx'; +// Save File +require_once __DIR__ . '/../Writer/IOFactory.php'; +$objWriter = Document_Word_Writer_IOFactory::createWriter($PHPWord, 'Word2007'); +$objWriter->save($fn); +// Download the file for testing +if($_SERVER['SERVER_NAME'] == 'localhost') +{ + exit; +} +if (file_exists($fn)) { + echo 'Prepare for download!!'; + header('Content-Description: File Transfer'); + header('Content-Type: application/octet-stream'); + header('Content-Disposition: attachment; filename='.basename($fn)); + header('Content-Transfer-Encoding: binary'); + header('Expires: 0'); + header('Cache-Control: must-revalidate'); + header('Pragma: public'); + header('Content-Length: ' . filesize($fn)); + ob_clean(); + flush(); + readfile($fn); + exit; +} +?> diff --git a/Document_Word_Writer/Examples/Link.php b/Document_Word_Writer/Examples/Link.php new file mode 100644 index 0000000..e554396 --- /dev/null +++ b/Document_Word_Writer/Examples/Link.php @@ -0,0 +1,27 @@ +createSection(); + +// Add hyperlink elements +$section->addLink('http://www.google.com', 'Best search engine', array('color'=>'0000FF', 'underline'=>Document_Word_Writer_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 +require_once __DIR__ . '/../Writer/IOFactory.php'; +$objWriter = Document_Word_Writer_IOFactory::createWriter($PHPWord, 'Word2007'); +$objWriter->save('/tmp/Link.docx'); +?> \ No newline at end of file diff --git a/Document_Word_Writer/Examples/ListItem.php b/Document_Word_Writer/Examples/ListItem.php new file mode 100644 index 0000000..c5b8488 --- /dev/null +++ b/Document_Word_Writer/Examples/ListItem.php @@ -0,0 +1,49 @@ +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'=>Document_Word_Writer_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'=>Document_Word_Writer_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'); + +// Save File +require_once __DIR__ . '/../Writer/IOFactory.php'; +$objWriter = Document_Word_Writer_IOFactory::createWriter($PHPWord, 'Word2007'); +$objWriter->save('/tmp/ListItem.docx'); +?> \ No newline at end of file diff --git a/Document_Word_Writer/Examples/Object.php b/Document_Word_Writer/Examples/Object.php new file mode 100644 index 0000000..a3c5142 --- /dev/null +++ b/Document_Word_Writer/Examples/Object.php @@ -0,0 +1,22 @@ +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 +require_once __DIR__ . '/../Writer/IOFactory.php'; +$objWriter = Document_Word_Writer_IOFactory::createWriter($PHPWord, 'Word2007'); +$objWriter->save('/tmp/Object.docx'); +?> diff --git a/Document_Word_Writer/Examples/Section.php b/Document_Word_Writer/Examples/Section.php new file mode 100644 index 0000000..2acd040 --- /dev/null +++ b/Document_Word_Writer/Examples/Section.php @@ -0,0 +1,28 @@ +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 +require_once __DIR__ . '/../Writer/IOFactory.php'; +$objWriter = Document_Word_Writer_IOFactory::createWriter($PHPWord, 'Word2007'); +$objWriter->save('/tmp/Section.docx'); +?> \ No newline at end of file diff --git a/Document_Word_Writer/Examples/Template.docx b/Document_Word_Writer/Examples/Template.docx new file mode 100755 index 0000000..cb90879 Binary files /dev/null and b/Document_Word_Writer/Examples/Template.docx differ diff --git a/Document_Word_Writer/Examples/Template.php b/Document_Word_Writer/Examples/Template.php new file mode 100644 index 0000000..ef6a2e4 --- /dev/null +++ b/Document_Word_Writer/Examples/Template.php @@ -0,0 +1,23 @@ +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'); +?> \ No newline at end of file diff --git a/Document_Word_Writer/Examples/Text.docx b/Document_Word_Writer/Examples/Text.docx new file mode 100644 index 0000000..c01e9b6 Binary files /dev/null and b/Document_Word_Writer/Examples/Text.docx differ diff --git a/Document_Word_Writer/Examples/Text.php b/Document_Word_Writer/Examples/Text.php new file mode 100644 index 0000000..f95b29d --- /dev/null +++ b/Document_Word_Writer/Examples/Text.php @@ -0,0 +1,29 @@ +createSection(); + +// Add text elements +$section->addText('Hello World!'); +$section->addTextBreak(2); + +$section->addText('I am inline styled.', array('name'=>'Verdana', 'color'=>'006699')); +$section->addTextBreak(2); + +$PHPWord->addFontStyle('rStyle', array('bold'=>true, 'italic'=>true, 'size'=>16)); +$PHPWord->addParagraphStyle('pStyle', array('align'=>'center', 'spaceAfter'=>100)); +$section->addText('I am styled by two style definitions.', 'rStyle', 'pStyle'); +$section->addText('I have only a paragraph style definition.', null, 'pStyle'); + + + +// Save File +require_once __DIR__ . '/../Writer/IOFactory.php'; +$objWriter = Document_Word_Writer_IOFactory::createWriter($PHPWord, 'Word2007'); +$objWriter->save('/tmp/Text.docx'); +?> \ No newline at end of file diff --git a/Document_Word_Writer/Examples/Textrun.php b/Document_Word_Writer/Examples/Textrun.php new file mode 100644 index 0000000..def9ddc --- /dev/null +++ b/Document_Word_Writer/Examples/Textrun.php @@ -0,0 +1,35 @@ +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'=>Document_Word_Writer_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 +require_once __DIR__ . '/../Writer/IOFactory.php'; +$objWriter = Document_Word_Writer_IOFactory::createWriter($PHPWord, 'Word2007'); +$objWriter->save('/tmp/Textrun.docx'); +?> \ No newline at end of file diff --git a/Document_Word_Writer/Examples/TitleTOC.php b/Document_Word_Writer/Examples/TitleTOC.php new file mode 100644 index 0000000..94922c1 --- /dev/null +++ b/Document_Word_Writer/Examples/TitleTOC.php @@ -0,0 +1,51 @@ +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 'Note: The pagenumbers in the TOC doesnt refresh automatically.'; + +// Save File +require_once __DIR__ . '/../Writer/IOFactory.php'; +$objWriter = Document_Word_Writer_IOFactory::createWriter($PHPWord, 'Word2007'); +$objWriter->save('/tmp/TitleTOC.docx'); +?> diff --git a/Document_Word_Writer/Examples/Watermark.php b/Document_Word_Writer/Examples/Watermark.php new file mode 100644 index 0000000..202b2da --- /dev/null +++ b/Document_Word_Writer/Examples/Watermark.php @@ -0,0 +1,21 @@ +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 = Document_Word_Writer_IOFactory::createWriter($PHPWord, 'Word2007'); +$objWriter->save('Watermark.docx'); +?> \ No newline at end of file diff --git a/Document_Word_Writer/Examples/_earth.JPG b/Document_Word_Writer/Examples/_earth.JPG new file mode 100644 index 0000000..28537b0 Binary files /dev/null and b/Document_Word_Writer/Examples/_earth.JPG differ diff --git a/Document_Word_Writer/Examples/_mars.jpg b/Document_Word_Writer/Examples/_mars.jpg new file mode 100644 index 0000000..584d317 Binary files /dev/null and b/Document_Word_Writer/Examples/_mars.jpg differ diff --git a/Document_Word_Writer/Examples/_sheet.xls b/Document_Word_Writer/Examples/_sheet.xls new file mode 100644 index 0000000..b8da43c Binary files /dev/null and b/Document_Word_Writer/Examples/_sheet.xls differ diff --git a/File_Convert_AbiToDocx/AbiToDocx.php b/File_Convert_AbiToDocx/AbiToDocx.php new file mode 100644 index 0000000..6b44965 --- /dev/null +++ b/File_Convert_AbiToDocx/AbiToDocx.php @@ -0,0 +1,34 @@ +save($fn); +//$xml = new XMLReader(); + +// Download the file for testing +if($_SERVER['SERVER_NAME'] == 'localhost') +{ + exit; +} +if (file_exists($fn)) { + echo 'Prepare for download!!'; + header('Content-Description: File Transfer'); + header('Content-Type: application/octet-stream'); + header('Content-Disposition: attachment; filename='.basename($fn)); + header('Content-Transfer-Encoding: binary'); + header('Expires: 0'); + header('Cache-Control: must-revalidate'); + header('Pragma: public'); + header('Content-Length: ' . filesize($fn)); + ob_clean(); + flush(); + readfile($fn); + exit; +} + + +?>