function export2odt($template_full_path, $template_mime_type, $data, $display, $save_path=""){ $data_vars = $data["data_vars"]; $data_blocks = $data["data_blocks"]; // instantiate a TBS OOo class $OOo = new clsTinyButStrongOOo; // setting the object if ($OOo->SetZipBinary('zip', true) == false) { // erreur zip non présent } if ($OOo->SetUnzipBinary('unzip', true) == false) { // erreur unzip non présent } if ($OOo->SetProcessDir('/tmp/') == false) { // erreur /tmp inaccessible } // create a new openoffice document from the template with an unique id $OOo->NewDocFromTpl($template_full_path); // merge data with OOo file content.xml $OOo->LoadXmlFromDoc('content.xml'); // load Data foreach($data_vars as $key => $value){ $GLOBALS[$key] = $value; } // Merge Data foreach ($data_blocks as $key => $value) { $OOo->MergeBlock($key, $value); } $OOo->SaveXmlToDoc(); if ($display){ if ($template_mime_type == "") $template_mime_type = $OOo->GetMimetypeDoc(); if ($template_mime_type == "") $template_mime_type = "sxw"; header('Content-type: '.$template_mime_type); header('Content-Length: '.filesize($OOo->GetPathnameDoc())); header('Content-Disposition: inline; filename=cv.'.$template_mime_type); $OOo->FlushDoc(); $OOo->RemoveDoc(); } else { if ($save_path != "") { rename($OOo->GetPathnameDoc(), $save_path); // affichage des document sauvés ????? } } }
private function reporteTBSOO($informe) { define('BASE', sfConfig::get('sf_app_module_dir') . '/informes/lib/'); require_once BASE . 'tbs_class_php5.php'; require_once BASE . 'tbsooo_class.php'; $OOo = new clsTinyButStrongOOo(); $OOo->noErr = true; $OOo->SetZipBinary('zip'); $OOo->SetUnzipBinary('unzip'); $OOo->SetProcessDir(sfConfig::get('sf_informe_dir')); $OOo->SetDataCharset('UTF8'); $OOo->NewDocFromTpl(sfConfig::get('sf_informe_dir') . DIRECTORY_SEPARATOR . $informe->getAdjunto()->getRuta()); $OOo->LoadXmlFromDoc('content.xml'); $aVariable = $this->leerTemplate($OOo->Source); $aDato = array(); //busco en las variables encontradas en el template y reemplaza contenido $aDato = $this->llenarVariables($aVariable); //agregando datos del registro informe $aDato['informe'] = $informe->toArray(); // variables adicionales dinamicas de los formulario if ($informe->getVariables()) { $aDato['variable'] = array(); $variables = explode(";", $informe->getVariables()); foreach ($variables as $variable) { $pos = stripos($variable, ":"); if ($pos) { $variable = substr($variable, 0, $pos); } $aDato['variable'] = array_merge($aDato['variable'], array($variable => $this->getRequestParameter($variable))); } } // lleno finalmente de diferente forma si es un array (ciclo) o no (variable comun) if (is_array($aDato)) { foreach ($aDato as $idx => $dato) { if ($this->isNotAssocArray($dato)) { $OOo->MergeBlock($idx, "array", $dato); } else { $OOo->MergeField($idx, $dato); } } } $OOo->SaveXmlToDoc(); // OJO hay headers locos para que funcione en internet explorer header('Content-type: ' . $OOo->GetMimetypeDoc()); //header("Content-Type: application/force-download"); //para que funcione en konqueror header("Cache-Control: public, must-revalidate"); header("Pragma: hack"); header('Content-Length: ' . filesize($OOo->GetPathnameDoc())); header('Content-Disposition: attachment; filename="informe' . $informe->getNombre() . '.odt"'); header("Content-Transfer-Encoding: binary"); $OOo->FlushDoc(); $OOo->RemoveDoc(); }
<?php include_once '../tbs_class.php'; include_once '../tbsooo_class.php'; // datas $x = 'Hello World'; // instantiate a TBS OOo class $OOo = new clsTinyButStrongOOo(); // setting the object $OOo->SetZipBinary('zip'); $OOo->SetUnzipBinary('unzip'); $OOo->SetProcessDir('tmp/'); // create a new openoffice document from the template with an unique id $OOo->NewDocFromTpl('tbsooo_us_examples_hello.sxw'); // merge data with openoffice file named 'content.xml' $OOo->LoadXmlFromDoc('content.xml'); $OOo->SaveXmlToDoc(); // display header('Content-type: ' . $OOo->GetMimetypeDoc()); header('Content-Length: ' . filesize($OOo->GetPathnameDoc())); $OOo->FlushDoc(); $OOo->RemoveDoc();
// I N C L U D E // ============================================================================ include_once '../tbs_class.php'; include_once '../tbsooo_class.php'; // ============================================================================ // R E Q U E S T // ============================================================================ $header = isset($_GET['header']) ? $_GET['header'] : 'content'; // ============================================================================ // I N I T // ============================================================================ // instantiate a TBS OOo class $OOo = new clsTinyButStrongOOo(); // set the binary ZIP //$OOo->SetZipBinary('/usr/bin/zip', true); if ($OOo->SetZipBinary('zip', true) == false) { die; } // set the binary UNZIP //$OOo->SetUnzipBinary('/usr/bin/unzip', true); if ($OOo->SetUnzipBinary('unzip', true) == false) { die; } // set the process directory if ($OOo->SetProcessDir('tmp/') == false) { die; } // ============================================================================ // D A T A S // ============================================================================ // globals