X-Git-Url: http://git.roojs.org/?a=blobdiff_plain;f=GnumericToExcel.php;h=824db5be5491c5ee92579984fafd65611e3d694f;hb=4f0a32091fae216359f985b9e6bf33af903035eb;hp=76c3ac31b537afe344702526678259a4819945fb;hpb=141fdefa8b905b24684665083703577e96728a92;p=Pman.Core diff --git a/GnumericToExcel.php b/GnumericToExcel.php index 76c3ac31..824db5be 100644 --- a/GnumericToExcel.php +++ b/GnumericToExcel.php @@ -28,13 +28,13 @@ class Pman_Core_GnumericToExcel extends Pman return true; } - function get() + function get($v, $opts=array()) { } function post($fname) { - $ml = (int) ini_get('suhosin.post.max_value_length'); + $ml = (int) ini_get('suhosin.post.max_value_length'); if (empty($_POST['xml'])) { header("HTTP/1.0 400 Internal Server Error"); die( $ml ? "Suhosin Patch enabled - try and disable it!!!" : 'no XML sent'); @@ -48,9 +48,9 @@ class Pman_Core_GnumericToExcel extends Pman $xml = iconv("UTF-8", "UTF-8//IGNORE", $xml); - //$xml = str_replace('é', 'e', $xml); + //$xml = str_replace('�', 'e', $xml); //$xml = str_replace("\xA0", ' ', $xml); - //$xml = str_replace("Ø", 'dia.',$xml); + //$xml = str_replace("�", 'dia.',$xml); //$this->addEvent("DOWNLOAD", false, isset($_REQUEST['title']) ? $_REQUEST['title'] : '???'); @@ -58,14 +58,27 @@ class Pman_Core_GnumericToExcel extends Pman if (!empty($_POST['format']) && $_POST['format']=='gnumeric') { if (empty($_POST['debug'])) { header('Content-type: application/x-gnumeric'); + header('Content-Disposition: attachment; filename="' .addslashes($fname). '.gnumeric"'); } else { header('Content-type: text/xml'); } echo $xml; exit; } + + $ext = '.xls'; + $outfmt = 'Gnumeric_Excel:excel_biff8'; + $mime = 'application/vnd.ms-excel'; + if (!empty($_POST['format']) && $_POST['format']=='xlsx') { + $outfmt = 'Gnumeric_Excel:xlsx'; + $ext = '.xlsx'; + $mime = 'aapplication/vnd.openxmlformats-officedocument.spreadsheetml.sheet'; + } + + + $srcTmp = ini_get('session.save_path') . '/' .uniqid('gnumeric_').'.gnumeric'; - $targetTmp = ini_get('session.save_path') . '/' .uniqid('gnumeric_').'.xls'; + $targetTmp = ini_get('session.save_path') . '/' .uniqid('gnumeric_') . $ext; // write the gnumeric file... $fh = fopen($srcTmp,'w'); fwrite($fh, $xml); @@ -73,10 +86,12 @@ class Pman_Core_GnumericToExcel extends Pman require_once 'System.php'; + $xvfb = System::which('xvfb-run'); + $ss = System::which('ssconvert'); - $cmd = $ss. + $cmd = $xvfb . " -a " . $ss. " --import-encoding=Gnumeric_XmlIO:sax" . - " --export-type=Gnumeric_Excel:excel_biff8 " . + " --export-type={$outfmt} " . $srcTmp . ' ' . $targetTmp . ' 2>&1'; // echo $cmd; //passthru($cmd);exit; @@ -89,9 +104,12 @@ class Pman_Core_GnumericToExcel extends Pman die("ERROR CONVERTING?:" . $cmd ."\n

OUTPUT:". htmlspecialchars($out)); } // unlink($srcTmp); + if (empty($fname)) { + $fname = basename($targetTmp); + } $fname .= preg_match('/\.xls/i', $fname) ? '' : '.xls'; // make sure it ends in xls.. - header('Content-type: application/vnd.ms-excel'); + header('Content-type: ' . $mime); header('Content-Disposition: attachment; filename="' .addslashes($fname). '"'); header('Content-length: '. filesize($targetTmp)); header("Content-Transfer-Encoding: binary"); @@ -108,5 +126,5 @@ class Pman_Core_GnumericToExcel extends Pman } - + }