function openoffice($tables) { // http://www.ibm.com/developerworks/web/library/wa-odf/index.html?ca=drs-#list10 include '../dbplumber/thirdparty/ods-php-0.1rc1/ods.php'; //include the class and wrappers $rawsheetcontent = '<?xml version="1.0" encoding="UTF-8"?> <office:document-content xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" xmlns:math="http://www.w3.org/1998/Math/MathML" xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" xmlns:ooo="http://openoffice.org/2004/office" xmlns:ooow="http://openoffice.org/2004/writer" xmlns:oooc="http://openoffice.org/2004/calc" xmlns:dom="http://www.w3.org/2001/xml-events" xmlns:xforms="http://www.w3.org/2002/xforms" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" office:version="1.0"><office:scripts/><office:font-face-decls><style:font-face style:name="Liberation Sans" svg:font-family="'Liberation Sans'" style:font-family-generic="swiss" style:font-pitch="variable"/><style:font-face style:name="DejaVu Sans" svg:font-family="'DejaVu Sans'" style:font-family-generic="system" style:font-pitch="variable"/></office:font-face-decls><office:automatic-styles><style:style style:name="co1" style:family="table-column"><style:table-column-properties fo:break-before="auto" style:column-width="2.267cm"/></style:style><style:style style:name="ro1" style:family="table-row"><style:table-row-properties style:row-height="0.453cm" fo:break-before="auto" style:use-optimal-row-height="true"/></style:style><style:style style:name="ta1" style:family="table" style:master-page-name="Default"><style:table-properties table:display="true" style:writing-mode="lr-tb"/></style:style></office:automatic-styles><office:body><office:spreadsheet></office:spreadsheet></office:body></office:document-content>'; $sheet = new ods(); $sheet->parse($rawsheetcontent); foreach ($tables as $table) { $rowno = 0; foreach (DB::query("SELECT * FROM \"{$table}\"") as $row) { $colno = 0; foreach ($row as $key => $val) { if ($rowno == 0) { $sheet->addCell($table, 0, $colno, $key, 'string'); } $sheet->addCell($table, $rowno + 1, $colno, Convert::raw2xml($val), is_numeric($val) ? 'float' : 'string'); $colno++; } $rowno++; } if (!$rowno) { $colno = 0; foreach (DB::fieldList($table) as $name => $spec) { $sheet->addCell($table, 0, $colno++, $name, 'string'); } } } saveOds($sheet, TEMP_FOLDER . '/new.ods'); //save the object to a ods file $output = file_get_contents(TEMP_FOLDER . '/new.ods'); unlink(TEMP_FOLDER . '/new.ods'); return $output; }
<?php // Load library require_once '../ods.php'; // Create Ods object $ods = new ods(); //Set vertical split $table = new odsTable('V Split'); $table->setVerticalSplit(1); $ods->addTable($table); //Set Horizontal split $table = new odsTable('H Split'); $table->setHorizontalSplit(1); $ods->addTable($table); // Both split $table = new odsTable('B Split'); $table->setVerticalSplit(1); $table->setHorizontalSplit(1); $ods->addTable($table); // Download the file $ods->downloadOdsFile("TableSplit.ods");
<?php // Load library require_once '../ods.php'; // Create Ods object $ods = new ods(); // Set properties $ods->setTitle("My title is cool"); $ods->setSubject("My subject is cool too"); $ods->setKeyword("ods, internet"); $ods->setDescription("I love odsPhpGenerator !!\n\nOk, i'm a programmer, sorry"); // Download the file $ods->downloadOdsFile("Properties.ods");
function newOds() { $content = '<?xml version="1.0" encoding="UTF-8"?> <office:document-content xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" xmlns:math="http://www.w3.org/1998/Math/MathML" xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" xmlns:ooo="http://openoffice.org/2004/office" xmlns:ooow="http://openoffice.org/2004/writer" xmlns:oooc="http://openoffice.org/2004/calc" xmlns:dom="http://www.w3.org/2001/xml-events" xmlns:xforms="http://www.w3.org/2002/xforms" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" office:version="1.0"><office:scripts/><office:font-face-decls><style:font-face style:name="Liberation Sans" svg:font-family="'Liberation Sans'" style:font-family-generic="swiss" style:font-pitch="variable"/><style:font-face style:name="DejaVu Sans" svg:font-family="'DejaVu Sans'" style:font-family-generic="system" style:font-pitch="variable"/></office:font-face-decls><office:automatic-styles><style:style style:name="co1" style:family="table-column"><style:table-column-properties fo:break-before="auto" style:column-width="2.267cm"/></style:style><style:style style:name="ro1" style:family="table-row"><style:table-row-properties style:row-height="0.453cm" fo:break-before="auto" style:use-optimal-row-height="true"/></style:style><style:style style:name="ta1" style:family="table" style:master-page-name="Default"><style:table-properties table:display="true" style:writing-mode="lr-tb"/></style:style></office:automatic-styles><office:body><office:spreadsheet><table:table table:name="Hoja1" table:style-name="ta1" table:print="false"><office:forms form:automatic-focus="false" form:apply-design-mode="false"/><table:table-column table:style-name="co1" table:default-cell-style-name="Default"/><table:table-row table:style-name="ro1"><table:table-cell/></table:table-row></table:table><table:table table:name="Hoja2" table:style-name="ta1" table:print="false"><table:table-column table:style-name="co1" table:default-cell-style-name="Default"/><table:table-row table:style-name="ro1"><table:table-cell/></table:table-row></table:table><table:table table:name="Hoja3" table:style-name="ta1" table:print="false"><table:table-column table:style-name="co1" table:default-cell-style-name="Default"/><table:table-row table:style-name="ro1"><table:table-cell/></table:table-row></table:table></office:spreadsheet></office:body></office:document-content>'; $obj = new ods(); $obj->parse($content); return $obj; }
<?php // Load library require_once '../ods.php'; // Create Ods object $ods = new ods(); // Create table named 'Cells' $table = new odsTable('Cells'); // Empty cell $row = new odsTableRow(); $row->addCell(new odsTableCellString("Empty cell")); $row->addCell(new odsTableCellEmpty()); $table->addRow($row); // String cell $row = new odsTableRow(); $row->addCell(new odsTableCellString("String cell")); $row->addCell(new odsTableCellString("String in my cell")); $table->addRow($row); // Email cell $row = new odsTableRow(); $row->addCell(new odsTableCellString("Email cell")); $row->addCell(new odsTableCellStringEmail("*****@*****.**")); $table->addRow($row); // Url cell $row = new odsTableRow(); $row->addCell(new odsTableCellString("Url cell")); $row->addCell(new odsTableCellStringUrl("http://odsphpgenerator.lapinator.net")); $table->addRow($row); // Foat cell $row = new odsTableRow(); $row->addCell(new odsTableCellString("Float cell"));
<?php // All file is writen in UTF-8 // Load library require_once '../ods.php'; // Create Ods object $ods = new ods(); // Create table named 'utf8' $table = new odsTable('utf8'); // Create french row $row = new odsTableRow(); $row->addCell(new odsTableCellString("French")); $row->addCell(new odsTableCellString("àôïîéèç...")); $table->addRow($row); // Create greek row $row = new odsTableRow(); $row->addCell(new odsTableCellString("Greek")); $row->addCell(new odsTableCellString("αβγδεζϕΩ...")); $table->addRow($row); // Create hebrew row $row = new odsTableRow(); $row->addCell(new odsTableCellString("Hebrew")); $row->addCell(new odsTableCellString("ש֓חרםא...")); $table->addRow($row); // Create arab row $row = new odsTableRow(); $row->addCell(new odsTableCellString("Arab")); $row->addCell(new odsTableCellString("ڤڦڪصى...")); $table->addRow($row); $row = new odsTableRow(); $row->addCell(new odsTableCellString("..."));
<?php // Load library require_once '../ods.php'; // Create Ods object $ods = new ods(); // Red text $style1 = new odsStyleTableCell(); $style1->setColor('#ff0000'); // Green background $style2 = new odsStyleTableCell(); $style2->setBackgroundColor('#00ff00'); // Blue border $style3 = new odsStyleTableCell(); $style3->setBorder('0.01cm solid #0000ff'); // Align start $style4_1 = new odsStyleTableCell(); $style4_1->setTextAlign('start'); // Align center $style4_2 = new odsStyleTableCell(); $style4_2->setTextAlign('center'); // Align end $style4_3 = new odsStyleTableCell(); $style4_3->setTextAlign('end'); // Align justify $style4_4 = new odsStyleTableCell(); $style4_4->setTextAlign('justify'); // Bold [bold, normal] $style5 = new odsStyleTableCell(); $style5->setFontWeight('bold'); // Italic [italic, normal]
<?php // Load library require_once '../ods.php'; // Create Ods object $ods = new ods(); // Create table $table = new odsTable('MergeCell'); $ods->addTable($table); // Merge 4 horizontal cell $row = new odsTableRow(); $cell = new odsTableCellString('Merge 4 cells'); $cell->setNumberColumnsSpanned(4); $row->addCell($cell); $table->addRow($row); // Merge 4 vertical cell $row = new odsTableRow(); $cell = new odsTableCellString('Merge 4 cells'); $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*7 cell $row = new odsTableRow(); $cell = new odsTableCellString('Merge 4*4 cells'); $cell->setNumberColumnsSpanned(4);
<?php // All file is writen in UTF-8 // Load library require_once '../ods.php'; // Create Ods object $ods = new ods(); // Create table named 'table 1' $table = new odsTable('table 1'); // Create the first row $row = new odsTableRow(); // Create 10 number cell for ($i = 0; $i < 10; $i++) { $row = new odsTableRow(); $row->addCell(new odsTableCellEmpty()); $row->addCell(new odsTableCellFloat(rand(0, 50))); $table->addRow($row); } // Add Formula cell // Forumla is writen in english language, it's internal format for formula $row = new odsTableRow(); $row->addCell(new odsTableCellString("Sum :")); $cell = new odsTableCellFloat(0); $cell->setFormula("SUM([.B1:.B10])"); $row->addCell($cell); $table->addRow($row); // Empty row $row = new odsTableRow(); $table->addRow($row); // 2nd example contatenate string $row = new odsTableRow();
public function ods($start, $end) { $data = $this->gendate($start, $end); $ods = new ods(); $table = new odsTable('table 1'); $table->setHorizontalSplit(1); $table->setVerticalSplit(3); // Set coluomn width $styleColumn = new odsStyleTableColumn(); $styleColumn->setColumnWidth("4cm"); $table->addTableColumn(new odsTableColumn($styleColumn)); $table->addTableColumn($column = new odsTableColumn($styleColumn = new odsStyleTableColumn())); $styleColumn->setColumnWidth("1.5cm"); $column->setRepeated($data['total_days']); // Set Title Style $styleTitle1 = new odsStyleTableCell(); $styleTitle1->setBorder("0.01cm solid #000000"); $styleTitle1->setFontWeight('bold'); $styleTitle2 = clone $styleTitle1; $styleTitle2->setTextAlign("center"); // Months style $row = new odsTableRow(); $row->addCell(new odsTableCellString("Months:", $styleTitle1)); foreach ($data['months'] as $moi) { $cell = new odsTableCellString($moi['title'], $styleTitle2); $cell->setNumberColumnsSpanned($moi['day']); $row->addCell($cell); } $table->addRow($row); $row = new odsTableRow(); $row->addCell(new odsTableCellString("Weeks :", $styleTitle1)); foreach ($data['weeks'] as $week) { $cell = new odsTableCellString($week['title'], $styleTitle2); $cell->setNumberColumnsSpanned($week['day']); $row->addCell($cell); } $table->addRow($row); $row = new odsTableRow(); $row->addCell(new odsTableCellString("Days:", $styleTitle1)); foreach ($data['days'] as $day) { $cell = new odsTableCellString($day['title'], $styleTitle2); $cell->setNumberColumnsSpanned($day['day']); $row->addCell($cell); } $table->addRow($row); foreach ($data['projects'] as $projet) { $row = new odsTableRow(); $row->addCell(new odsTableCellString($projet['title'], $styleTitle1)); if ($projet["shift"]) { $cell = new odsTableCellEmpty(); $cell->setNumberColumnsRepeated($projet["shift"]); $row->addCell($cell); } $styleX = clone $styleTitle2; $styleX->setBackgroundColor($projet[color]); $cell = new odsTableCellString($projet['title'], $styleX); $cell->setNumberColumnsSpanned($projet['days']); $row->addCell($cell); $table->addRow($row); } $ods->addTable($table); $ods->downloadOdsFile("tab.ods"); exit; }
<?php // This example is writen in UTF-8 // Load library require_once '../ods.php'; // Create Ods object $ods = new ods(); // Create table named 'table 1' $table1 = new odsTable('table 1'); $row = new odsTableRow(); $row->addCell(new odsTableCellString("Hello")); $row->addCell(new odsTableCellString("World")); $table1->addRow($row); $ods->addTable($table1); // Create table named 'table 2' $table2 = new odsTable('table 2'); $row = new odsTableRow(); $row->addCell(new odsTableCellString("Rand1")); $row->addCell(new odsTableCellString("=")); $row->addCell(new odsTableCellString(rand())); $table2->addRow($row); $row = new odsTableRow(); $row->addCell(new odsTableCellString("Rand2")); $row->addCell(new odsTableCellString("=")); $row->addCell(new odsTableCellString(rand())); $table2->addRow($row); $ods->addTable($table2); //Select 'table 2' $ods->setDefaultTable($table2); // Download the file $ods->downloadOdsFile("multiTable.ods");
<?php require_once dirname(dirname(dirname(__FILE__))) . '/config.php'; CheckTourSession(true); require_once 'Common/Fun_FormatText.inc.php'; require_once 'Common/Lib/Obj_RankFactory.php'; require_once 'Common/ods/ods.php'; $excel = new ods(); //$TXT=array(); require_once 'ResultInd.inc.php'; require_once 'ResultTeam.inc.php'; $excel->save($_SESSION['TourCode'] . '.ods', 'a'); die; //$zip = new ZipArchive(); // //$filename = tempnam("/tmp", "FontModule.zip"); // //if ($zip->open($filename, ZIPARCHIVE::CREATE)!==TRUE) { // exit("cannot open <$filename>\n"); //} // //foreach($TXT as $Event => $Data) { // $zip->addFromString("$Event.txt", $Data); //} // ///* //echo "numfiles: " . $zip->numFiles . "\n"; //echo "status:" . $zip->status . "\n"; //*/ // //$zip->close();
<?php // Load library require_once '../ods.php'; // Create Ods object $ods = new ods(); $table = new odsTable('Column Width'); // create column width 1cm $styleColumn = new odsStyleTableColumn(); $styleColumn->setColumnWidth("1cm"); $column1 = new odsTableColumn($styleColumn); // create column width 7cm $styleColumn = new odsStyleTableColumn(); $styleColumn->setColumnWidth("7cm"); $column2 = new odsTableColumn($styleColumn); // add 2 1cm column $table->addTableColumn($column1); $table->addTableColumn($column1); // add 1 7cm column $table->addTableColumn($column2); // Create data $table->addRow($row = new odsTableRow()); $row->addCell(new odsTableCellString("1cm")); $row->addCell(new odsTableCellString("1cm")); $row->addCell(new odsTableCellString("7cm ...")); // Add table to ods $ods->addTable($table); // Download the file $ods->downloadOdsFile("ColumnWidth.ods");
function parseOdsZip($dir, $file) { $src_file = $dir . '/' . $file . '.ods'; $temp_dir = $dir . '/' . $file . '.ods_temp'; if (is_dir($temp_dir)) { DelRec($temp_dir); } else { } mkdir($temp_dir); $zip = new ZipArchive(); $zip->open($src_file); $zip->extractTo($temp_dir); $zip->close(); $obj = new ods(); $obj->parse(file_get_contents($temp_dir . '/content.xml')); DelRec($temp_dir); return $obj; }