18 define(
"SEPCHAR",
';');
19 define(
"ALTSEPCHAR",
' --- ');
30 if (
$name ==
"TABLE:TABLE-ROW") {
32 if (isset($rows[$nrow])) {
35 foreach ($rows[$nrow] as $k => $v) {
36 if (!isset($rows[$nrow][$idx])) $rows[
$nrow][$idx] =
'';
39 ksort($rows[$nrow], SORT_NUMERIC);
43 $rows[
$nrow] = array();
46 if (
$name ==
"TABLE:TABLE-CELL") {
49 if ($attrs[
"TABLE:NUMBER-COLUMNS-REPEATED"]) {
50 $colrepeat = intval($attrs[
"TABLE:NUMBER-COLUMNS-REPEATED"]);
53 if (
$name ==
"TEXT:P") {
54 if (strlen($rows[$nrow][$ncol]) > 0) $rows[
$nrow][
$ncol].=
'\n';
56 if (
$name ==
"TEXT:S" && $incell) {
57 $count = intval($attrs[
"TEXT:C"]);
61 $celldata .= str_repeat(
" ", $count);
68 if (
$name ==
"TABLE:TABLE-ROW") {
72 if (strlen($rows[$nrow][$i]) > 0) {
77 array_splice($rows[$nrow], $i + 1);
81 if (
$name ==
"TABLE:TABLE-CELL") {
102 if ($inrow && $incell) {
103 $celldata.= preg_replace(
'/\s/u',
' ', preg_replace(
'/^\s*[\r\n]\s*$/ms',
'', str_replace(
SEPCHAR,
ALTSEPCHAR, $data)));
112 $xml_parser = xml_parser_create();
114 xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING,
true);
115 xml_parser_set_option($xml_parser, XML_OPTION_SKIP_WHITE, 0);
116 xml_set_element_handler($xml_parser,
"startElementOds",
"endElementOds");
117 xml_set_character_data_handler($xml_parser,
"characterDataOds");
119 if (!xml_parse($xml_parser, $xmlcontent)) {
120 return (sprintf(
"error XML : %s line %d", xml_error_string(xml_get_error_code($xml_parser)) , xml_get_current_line_number($xml_parser)));
123 xml_parser_free($xml_parser);
125 foreach ($rows as $k => $row) {
126 $fcsv.= implode(
SEPCHAR, $row) .
"\n";
132 if (!file_exists(
$odsfile))
return "file $odsfile not found";
133 $cibledir = uniqid(
getTmpDir() .
"/ods");
135 $cmd = sprintf(
"unzip -j %s content.xml -d %s >/dev/null", escapeshellarg(
$odsfile) , escapeshellarg($cibledir));
138 $contentxml = $cibledir .
"/content.xml";
139 if (file_exists($contentxml)) {
140 $content = file_get_contents($contentxml);
150 print
"odsfile needed :usage --odsfile=<ods file> [--csvfile=<csv file output>]\n";
160 if ($n > 0) print sprintf(_(
"csv file <%s> wroted") .
"\n",
$csvfile);
165 if (
$err !=
"") print
"ERROR:$err\n";