Skip to content

Commit 8a89969

Browse files
dilshodclaude
andcommitted
Add safe handling of Excel error values with ignore_invalid_char_data option
- Add ignore_invalid_char_data option to suppress errors from Excel error values like #N/A, #VALUE!, etc. - Fix ValueError/OverflowError handling to use empty string instead of None to prevent runtime crashes - Addresses the core issue from PR #244 with a safer implementation that avoids string concatenation errors - All existing tests pass, maintaining backward compatibility Resolves the problem described in #244 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent ca24b29 commit 8a89969

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

xlsx2csv.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ def __init__(self, xlsxfile, **options):
219219
options.setdefault("lineterminator", "\n")
220220
options.setdefault("outputencoding", "utf-8")
221221
options.setdefault("skip_hidden_rows", True)
222+
options.setdefault("ignore_invalid_char_data", False)
222223

223224
self.options = options
224225
self.py3 = sys.version_info[0] == 3
@@ -966,7 +967,12 @@ def handleCharData(self, data):
966967
self.data = ("%f" % data).rstrip('0').rstrip('.')
967968

968969
except (ValueError, OverflowError): # this catch must be removed, it's hiding potential problems
969-
raise XlsxValueError("Error: potential invalid date format.")
970+
if self.options['ignore_invalid_char_data']:
971+
# If invalid character data or excel formulas are encountered,
972+
# we set the data to empty string to avoid conversion errors
973+
self.data = ""
974+
else:
975+
raise XlsxValueError("Error: potential invalid date format.")
970976

971977
def handleStartElement(self, name, attrs):
972978
has_namespace = name.find(":") > 0

0 commit comments

Comments
 (0)