@@ -1074,11 +1074,11 @@ def _range(self, rangeStr):
10741074 t = t // 26 - 1
10751075
10761076
1077- def convert_recursive (path , sheetid , outfile , kwargs ):
1077+ def convert_recursive (path , sheetid , outfile , kwargs , continue_on_error = False ):
10781078 for name in os .listdir (path ):
10791079 fullpath = os .path .join (path , name )
10801080 if os .path .isdir (fullpath ):
1081- convert_recursive (fullpath , sheetid , outfile , kwargs )
1081+ convert_recursive (fullpath , sheetid , outfile , kwargs , continue_on_error )
10821082 else :
10831083 outfilepath = outfile
10841084 if isinstance (outfilepath , type (sys .stdout )):
@@ -1091,8 +1091,15 @@ def convert_recursive(path, sheetid, outfile, kwargs):
10911091 print ("Converting %s to %s" % (fullpath , outfilepath ))
10921092 try :
10931093 Xlsx2csv (fullpath , ** kwargs ).convert (outfilepath , sheetid )
1094- except zipfile .BadZipfile :
1095- raise InvalidXlsxFileException ("File %s is not a zip file" % fullpath )
1094+ except Exception as e :
1095+ if continue_on_error :
1096+ print ("ERROR processing file '%s': %s" % (fullpath , str (e )), file = sys .stderr )
1097+ continue
1098+ else :
1099+ if isinstance (e , zipfile .BadZipfile ):
1100+ raise InvalidXlsxFileException ("File %s is not a zip file" % fullpath )
1101+ else :
1102+ raise
10961103
10971104
10981105def main ():
@@ -1166,6 +1173,8 @@ def main():
11661173 help = "sheet number to convert" )
11671174 parser .add_argument ("--include-hidden-rows" , dest = "include_hidden_rows" , default = False , action = "store_true" ,
11681175 help = "include hidden rows" )
1176+ parser .add_argument ("--continue-on-error" , dest = "continue_on_error" , default = False , action = "store_true" ,
1177+ help = "continue processing remaining files when an error occurs during batch processing" )
11691178
11701179 if argparser :
11711180 options = parser .parse_args ()
@@ -1252,7 +1261,7 @@ def main():
12521261 outfile = options .outfile or sys .stdout
12531262 try :
12541263 if os .path .isdir (options .infile ):
1255- convert_recursive (options .infile , sheetid , outfile , kwargs )
1264+ convert_recursive (options .infile , sheetid , outfile , kwargs , options . continue_on_error )
12561265 elif not os .path .exists (options .infile ) and options .infile != "-" :
12571266 raise InvalidXlsxFileException ("Input file not found!" )
12581267 else :
0 commit comments