File: //proc/23796/root/lib/php/phpoffice/phpspreadsheet/tool.php
#!/usr/bin/php
<?php
function IsFileFormatValid($format) {
$whiteList = array("Excel2007", "Excel5", "OOCalc", "SYLK", "Excel2003XML", "Gnumeric");
return in_array($format, $whiteList);
}
function Usage()
{
echo "Copyright (c) 2000-2015 Synology Inc. All rights reserved.\n";
echo "Usage: " . basename(__FILE__) . " [options]\n";
echo " -i<string> : input file path\n";
echo " -f<string> : input file format(Excel2007, Excel5, OOCalc, SYLK, Excel2003XML, Gnumeric) case-sensitive\n";
echo " -h : show help\n";
}
// Check args
$optCfg = "i:f:h::";
$options = getopt($optCfg);
$format = empty($options['f']) ? "" : $options['f'];
$inputPath = empty($options['i']) ? "" : $options['i'];
if (isset($options['h']) || empty($format) || empty($inputPath)) {
Usage();
exit(1);
}
if (!IsFileFormatValid($format)) {
echo "wrong file format: " . $format . " \n";
exit(1);
}
// Load PHPExcel modules
use PhpOffice\PhpSpreadsheet\IOFactory;
require_once __DIR__ . '/vendor/autoload.php';
// Load input file with specified reader
$spreadsheet = IOFactory::load($inputPath);
// Create cvs writer
$writer = IOFactory::createWriter($spreadsheet, 'Csv');
$writer->setDelimiter(', ')->setEnclosure('')->setLineEnding("\n")->setPreCalculateFormulas(false);
// Output each sheet
$sheetCount = $spreadsheet->getSheetCount();
for ($i = 0; $i < $sheetCount; $i++) {
if (0 !== $i) {
echo "---\n";
}
$writer->setSheetIndex($i);
$writer->save('php://stdout');
}
?>