X-Git-Url: http://git.roojs.org/?p=Pman.Core;a=blobdiff_plain;f=JsonToExcel.php;h=75a24fe85c76eae82211dc3bf41aac0697f09bb3;hp=251a999f4486d7152ee3219a311a67e87fddbf5a;hb=1524f8b36295809a3eedd6da3c6494f8aa0d86f5;hpb=e468181830cb9cb77e2cb5a51cb5b04d14f35905 diff --git a/JsonToExcel.php b/JsonToExcel.php index 251a999f..75a24fe8 100644 --- a/JsonToExcel.php +++ b/JsonToExcel.php @@ -28,7 +28,7 @@ class Pman_Core_JsonToExcel extends Pman return true; } - function get() + function get($v, $opts=array()) { $this->jerr("invalid get"); } @@ -44,17 +44,38 @@ class Pman_Core_JsonToExcel extends Pman header("HTTP/1.0 400 Internal Server Error"); die("Missing json attribute"); } - $_json = $_POST['_json']; + $json = json_decode($_POST['_json']); - $worksheet = $workbook->addWorksheet($cfg['workbook']); + + require_once 'Spreadsheet/Excel/Writer.php'; + // Creating a workbook + $outfile2 = $this->tempName('xls'); + // var_dump($outfile2); + $workbook = new Spreadsheet_Excel_Writer($outfile2); + //$workbook = new Spreadsheet_Excel_Writer(); + $workbook->setVersion(8); + // sending HTTP headers + $worksheet = $workbook->addWorksheet("Sheet 1"); if (is_a($worksheet, 'PEAR_Error')) { die($worksheet->toString()); } //print_R($worksheet); - $worksheet->setInputEncoding('UTF-8'); - - + $worksheet->setInputEncoding('UTF-8'); + + for ($r = 0; $r < count($json); $r++) { + $row = $json[$r]; + for ($c = 0; $c < count($row); $c++) { + $worksheet->write($r, $c, $row[$c]); + } + + } + $workbook->close(); + + require_once 'File/Convert.php'; + $fc= new File_Convert($outfile2, "application/vnd.ms-excel"); + $fn = $fc->convert("application/vnd.ms-excel"); + $fc->serve('attachment','excel-'.date('Y-m-d-H-i-s').'.xls'); // can fix IE Mess + unlink($outfile2); } - - + }