2 ini_set('include_path', __DIR__ . '/../../..:.');
3 require_once __DIR__ . '/../Writer.php';
4 require_once __DIR__ . '/../Writer/Style/Cell.php';
7 $PHPWord = new Document_Word_Writer();
9 // New portrait section
10 $section = $PHPWord->createSection();
12 // Define table style arrays
13 $styleTable = array('borderSize'=>6, 'borderColor'=>'006699', 'cellMargin'=>80);
14 $styleFirstRow = array('borderBottomSize'=>18, 'borderBottomColor'=>'0000FF', 'bgColor'=>'66BBFF');
16 // Define cell style arrays
17 $styleCell = array('valign'=>'center');
18 $styleCellBTLR = array('valign'=>'center', 'textDirection'=>Document_Word_Writer_Style_Cell::TEXT_DIR_BTLR);
20 // Define font style for first row
21 $fontStyle = array('bold'=>true, 'align'=>'center');
24 $PHPWord->addTableStyle('myOwnTableStyle', $styleTable, $styleFirstRow);
27 $table = $section->addTable('myOwnTableStyle');
33 $table->addCell(2000, $styleCell)->addText('Row 1', $fontStyle);
34 $table->addCell(2000, $styleCell)->addText('Row 2', $fontStyle);
35 $table->addCell(2000, $styleCell)->addText('Row 3', $fontStyle);
36 $table->addCell(2000, $styleCell)->addText('Row 4', $fontStyle);
37 $table->addCell(500, $styleCellBTLR)->addText('Row 5', $fontStyle);
39 // Add more rows / cells
40 for($i = 1; $i <= 10; $i++) {
42 $table->addCell(2000)->addText("Cell $i");
43 $table->addCell(2000)->addText("Cell $i");
44 $table->addCell(2000)->addText("Cell $i");
45 $table->addCell(2000)->addText("Cell $i");
47 $text = ($i % 2 == 0) ? 'X' : '';
48 $table->addCell(500)->addText($text);
53 require_once __DIR__ . '/../Writer/IOFactory.php';
54 $objWriter = Document_Word_Writer_IOFactory::createWriter($PHPWord, 'Word2007');
55 $objWriter->save('/tmp/AdvancedTable.docx');