Skip to content

Commit 1d57167

Browse files
committed
#302 add --continue-on-error option
1 parent efd06ef commit 1d57167

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

CHANGELOG

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
version 0.8.4 (2025-Oct-1):
2+
* Add --continue-on-error option for batch processing to continue when individual files fail
3+
14
version 0.8.3 (2024-Jul-29):
25
* Fix bug when missing workbook relationship
36
* Update pyproject.toml with python support

xlsx2csv.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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

10981105
def 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

Comments
 (0)