-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathconvert.php
More file actions
executable file
·50 lines (40 loc) · 1.37 KB
/
convert.php
File metadata and controls
executable file
·50 lines (40 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
/*
$json =file_get_contents('php://stdin');//rawurldecode($_SERVER['argv'][1]);
$obj=json_decode($json,true);
//echo '\r\ndebug1:\r\n';
//echo "\r\n|".$json."|\r\n";
//var_dump($obj);
if(!$obj)
{
$obj=json_decode(stripslashes($json));
//echo '\r\ndebug2:\r\n';
//var_dump($obj);
}
*/
// php -f convert.php myfile.xlsx myfile.csv
if($_SERVER['argc'] < 3) {
echo "usage: php -f convert.php input.xlsx output.js\r\n supported formats: .xlsx or .xls or .ods or .csv ";
exit(2);
}
error_reporting(E_ALL);
date_default_timezone_set('Asia/Jerusalem'); //
ini_set("auto_detect_line_endings", true); // https://github.com/shimondoodkin/node_spreadsheet/issues/2
/** PHPExcel_IOFactory */
require_once 'phpexcel/Classes/PHPExcel/IOFactory.php';
require_once 'phpexcel/Classes/PHPExcel/Writer/JSON.php';
if (!file_exists($_SERVER['argv'][1])) {
exit($_SERVER['argv'][1] . " not found.\n");
}
// echo date('H:i:s') . " Loading file\n";
$objPHPExcel = PHPExcel_IOFactory::load($_SERVER['argv'][1]);
// echo date('H:i:s') . " Done\n";
//$objCSV = new PHPExcel_Writer_CSV($objPHPExcel);
$objCSV = new PHPExcel_Writer_JSON($objPHPExcel);
$objCSV->setUseBOM(false);
// echo date('H:i:s') . " Saveing file\n";
$objCSV->save($_SERVER['argv'][2]);
//$objCSV->save('/tmp/json42');
// echo date('H:i:s') . " Done\n";
// if input is csv then convert charset : iso-8859-8 -> utf-8
?>