odsPhpGenerator 是一個可以透過php 匯出 ods 套件
紀錄一下他的用法
安裝odsPhpGenerator
$ composer require lapinator/ods-php-generator
<?php
// Load library
require_once '../vendor/autoload.php';
use odsPhpGenerator\ods;
use odsPhpGenerator\odsStyleTableCell;
use odsPhpGenerator\odsTable;
use odsPhpGenerator\odsTableRow;
use odsPhpGenerator\odsTableCellString;
use odsPhpGenerator\odsCoveredTableCell;
// Create Ods object
$ods = new ods();
// Style border
$black_border_style = new odsStyleTableCell();
$black_border_style->setBorder('0.01cm solid #000000');
$blue_border_style = new odsStyleTableCell();
$blue_border_style->setBorder('0.01cm solid #0000ff');
// Create table
$table = new odsTable('MergeCell');
$ods->addTable($table);
// Merge 4 horizontal cell
$row = new odsTableRow();
$cell = new odsTableCellString('水平合併四列欄位', $black_border_style);
$cell->setNumberColumnsSpanned(4);
$row->addCell( $cell );
$table->addRow($row);
// Merge 4 vertical cell
$row = new odsTableRow();
$cell = new odsTableCellString('垂直合併四行欄位');
$cell->setNumberRowsSpanned(4);
$row->addCell( $cell );
$table->addRow($row);
for($i=0; $i<3; $i++) { // You need add cell odsCoveredTableCell, in covered cell except the first row (implicit)
$row = new odsTableRow();
$row->addCell( new odsCoveredTableCell() );
$table->addRow($row);
}
// Merge 4*4 cell
$row = new odsTableRow();
$cell = new odsTableCellString('合併 4*4 列行', $blue_border_style);
$cell->setNumberColumnsSpanned(4);
$cell->setNumberRowsSpanned(4);
$row->addCell( $cell );
$table->addRow($row);
for($i=0; $i<3; $i++) { // You need add cell odsCoveredTableCell, in covered cell except the first row (implicit)
$row = new odsTableRow();
$row->addCell( new odsCoveredTableCell() );
$row->addCell( new odsCoveredTableCell() );
$row->addCell( new odsCoveredTableCell() );
$row->addCell( new odsCoveredTableCell() );
$table->addRow($row);
}
// Second Columns Merge 4 vertical cell
$row = new odsTableRow();
$cell = new odsTableCellString('Second Columns Merge 4 cells');
$cell->setNumberRowsSpanned(4);
$row->addCell( new odsCoveredTableCell() );
$row->addCell( $cell );
$row->addCell( new odsCoveredTableCell() );
$row->addCell( new odsCoveredTableCell() );
$table->addRow($row);
// Download the file
$ods->downloadOdsFile("MergeCell.ods");
?>
參考引用網站:
https://github.com/Lapinator/odsPhpGenerator
https://getcomposer.ycnets.com/
留言列表