add exmpales
[pear-examples] / Document_Word_Writer / Examples / BasicTable.php
1 <?php
2 ini_set('include_path', __DIR__  . '/../../..:.');
3 require_once __DIR__ . '/../Writer.php';
4 // New Word Document
5 $PHPWord = new Document_Word_Writer();
6
7 // New portrait section
8 $section = $PHPWord->createSection();
9
10 // Add table
11 $table = $section->addTable();
12
13 $cellStyle = array('bgColor'=>'C0C0C0');
14
15 $table = $section->addTable();
16 $table->addRow(1000);
17 $table->addCell(2000, $cellStyle)->addText('Cell 1');
18 $table->addCell(2000, $cellStyle)->addText('Cell 2');
19 $table->addCell(2000, $cellStyle)->addText('Cell 3');
20 $table->addRow();
21 $table->addCell(2000)->addText('Cell 4');
22 $table->addCell(2000)->addText('Cell 5');
23 $table->addCell(2000)->addText('Cell 6');
24
25 // Save File
26 require_once __DIR__ . '/../Writer/IOFactory.php';
27 $objWriter = Document_Word_Writer_IOFactory::createWriter($PHPWord, 'Word2007');
28 $objWriter->save('/tmp/BasicTable.docx');
29
30 // Download the file for testing
31 if($_SERVER['SERVER_NAME'] == 'localhost')
32 {
33     exit;
34 }
35 $file = '/tmp/BasicTable.docx';
36 if (file_exists($file)) {
37     echo 'Prepare for download!!';
38     header('Content-Description: File Transfer');
39     header('Content-Type: application/octet-stream');
40     header('Content-Disposition: attachment; filename='.basename($file));
41     header('Content-Transfer-Encoding: binary');
42     header('Expires: 0');
43     header('Cache-Control: must-revalidate');
44     header('Pragma: public');
45     header('Content-Length: ' . filesize($file));
46     ob_clean();
47     flush();
48     readfile($file);
49     exit;
50 }
51
52 ?>