16 define(
"SEPCHAR",
';');
17 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") {
50 if (isset($attrs[
"TABLE:NUMBER-COLUMNS-REPEATED"])) {
51 $colrepeat = intval($attrs[
"TABLE:NUMBER-COLUMNS-REPEATED"]);
54 if ($name ==
"TEXT:P") {
55 if ((isset($rows[$nrow][$ncol])) && strlen($rows[$nrow][$ncol]) > 0) $rows[
$nrow][
$ncol].=
'\n';
62 if ($name ==
"TABLE:TABLE-ROW") {
66 if (strlen($rows[$nrow][$i]) > 0) {
71 array_splice($rows[$nrow], $i + 1);
74 if ($name ==
"TEXT:S") {
77 if ($name ==
"TABLE:TABLE-CELL") {
80 if ($celldata ===
'') {
102 if ($inrow && $incell) {
103 $celldata.= preg_replace(
'/\s/u',
' ', preg_replace(
'/^\s*[\r\n]\s*$/ms',
'', str_replace(
SEPCHAR,
ALTSEPCHAR,
$data)));
113 if (isset($attrs[
'OFFICE:VALUE-TYPE'])) {
114 $type = strtoupper($attrs[
'OFFICE:VALUE-TYPE']);
115 $propName =
'OFFICE:' .
$type .
'-VALUE';
116 if (isset($attrs[$propName])) {
117 $value = (string)$attrs[$propName];
121 if (
$value ==
'' && isset($attrs[
'OFFICE:VALUE'])) {
122 $value = (string)$attrs[
'OFFICE:VALUE'];
130 $xml_parser = xml_parser_create();
132 xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING,
true);
133 xml_parser_set_option($xml_parser, XML_OPTION_SKIP_WHITE, 0);
134 xml_set_element_handler($xml_parser,
"startElementOds",
"endElementOds");
135 xml_set_character_data_handler($xml_parser,
"characterDataOds");
137 if (!xml_parse($xml_parser, $xmlcontent)) {
138 return (sprintf(
"error XML : %s line %d", xml_error_string(xml_get_error_code($xml_parser)) , xml_get_current_line_number($xml_parser)));
141 xml_parser_free($xml_parser);
143 foreach ($rows as $k => $row) {
144 $fcsv.= implode(
SEPCHAR, $row) .
"\n";
151 if (!file_exists(
$odsfile))
return "file $odsfile not found";
152 $cibledir = uniqid(
getTmpDir() .
"/ods");
154 $cmd = sprintf(
"unzip -j %s content.xml -d %s >/dev/null", escapeshellarg(
$odsfile) , escapeshellarg($cibledir));
157 $contentxml = $cibledir .
"/content.xml";
158 if (file_exists($contentxml)) {
159 $content = file_get_contents($contentxml);
169 $usage->setDefinitionText(
"Convert OpenDocument Spreadsheet to csv (semicolon)");
180 if ($n > 0)
print sprintf(_(
"csv file <%s> wroted") .
"\n",
$csvfile);
ods2content($odsfile, &$content)
xmlcontent2csv($xmlcontent, &$fcsv)
foreach($argv as $arg) $cmd
getOfficeTypedValue($attrs)
endElementOds($parser, $name)
characterDataOds($parser, $data)
startElementOds($parser, $name, $attrs)
Verify arguments for wsh programs.