11 * format = [empty=xls] , 'gnumeric' (download format)
12 * debug = true => download xml.
18 require_once 'Pman.php';
19 class Pman_Core_JsonToExcel extends Pman
23 $au = $this->getAuthUser();
25 die("NOT authenticated");
27 $this->authUser = $au;
33 $this->jerr("invalid get");
35 function post($fname) {
37 $ml = (int) ini_get('suhosin.post.max_value_length');
38 if (empty($_POST['_json'])) {
39 header("HTTP/1.0 400 Internal Server Error");
40 die( $ml ? "Suhosin Patch enabled - try and disable it!!!" : 'no JSON sent');
43 if (empty($_POST['_json'])) {
44 header("HTTP/1.0 400 Internal Server Error");
45 die("Missing json attribute");
47 $json = json_decode($_POST['_json']);
50 require_once 'Spreadsheet/Excel/Writer.php';
51 // Creating a workbook
52 $outfile2 = $this->tempName('xls');
53 // var_dump($outfile2);
54 $workbook = new Spreadsheet_Excel_Writer($outfile2);
55 //$workbook = new Spreadsheet_Excel_Writer();
56 $workbook->setVersion(8);
57 // sending HTTP headers
58 $worksheet = $workbook->addWorksheet("Sheet 1");
59 if (is_a($worksheet, 'PEAR_Error')) {
60 die($worksheet->toString());
62 //print_R($worksheet);
63 $worksheet->setInputEncoding('UTF-8');
65 for ($r = 0; $r < count($json); $r++) {
67 for ($c = 0; $c < count($row); $c++) {
68 $worksheet->write($r, $c, $row[$c]);
74 require_once 'File/Convert.php';
75 $fc= new File_Convert($outfile2, "application/vnd.ms-excel");
76 $fn = $fc->convert("application/vnd.ms-excel");
77 $fc->serve('attachment','excel-'.date('Y-m-d-H-i-s').'.xls'); // can fix IE Mess