/* * Convert Excel to CSV * V 1.0 * Dyrk.org * (c) Dave Hill 2016 - 2017 */ if (! isset($argv[1]) || ! is_file($argv[1])) exit("[usage] ./$argv[0] produits.xls\n"); // Text Dictionnary $handle = fopen("zip://$argv[1]#xl/sharedStrings.xml", 'r'); if ($handle){ $result = ''; while (!feof($handle)) $result .= fread($handle, 8192); fclose($handle); $content = str_replace("\n", "", $result); if (preg_match_all('/\(.*?)\<\/si>/s', $result, $match)){ $dico = $match[1]; foreach ($match[1] as $k => $v) $dico[$k] = strip_tags($v); } } if (($zip = zip_open($argv[1]))) { while ($zip_entry = zip_read($zip)) { if (! zip_entry_open($zip, $zip_entry)) continue; $filename = zip_entry_name($zip_entry); if (preg_match("/xl\/worksheets\/sheet([0-9]{0,3}).xml/",$filename,$fileId)) { // Open File $filesize = intval(zip_entry_filesize($zip_entry)); $content = zip_entry_read($zip_entry, $filesize); echo "\n\n\n\nFilename :; $filename;\n\n\n\n"; $rowReg = '/\\(.*?)\<\/v>|\/\>)/s'; if (preg_match_all($colReg, $v, $row)){ $rowData = $row[2]; // Extract All Record from Line foreach ($rowData as $k => $v){ if (strstr($row[0][$k], 't="s"')) $v = str_replace("\n",'\n',$dico[$v]); echo '"'.addslashes(($v=='/>')?'':$v).'";'; } echo "\n"; } } } } zip_entry_close($zip_entry); } zip_close($zip); }