Skip to content

Commit 42955e7

Browse files
authored
Fix for issue 6 (#9)
* Added code and test to account for empty cells 'None' > '' * Added code and test to account for empty cells 'None' > '' Fixed paths, removed print statement Co-authored-by: BYB <privateemail>
1 parent bb281eb commit 42955e7

2 files changed

Lines changed: 5 additions & 4 deletions

File tree

sheet2dict/main.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ def _parse_sheet_items(self, sheet: Worksheet, parsing_all_sheets: bool = False)
4646
sheet_title = sheet.title
4747

4848
def item(row, col):
49-
return (
50-
sheet.cell(row=1, column=col).value,
51-
str(sheet.cell(row=row, column=col).value),
52-
)
49+
if sheet.cell(row=row, column=col).value is None:
50+
return (sheet.cell(row=1, column=col).value, '')
51+
else:
52+
return (sheet.cell(row=1, column=col).value, str(sheet.cell(row=row, column=col).value))
5353

5454
list_to_append = (
5555
self.sheet_items[sheet_title] if parsing_all_sheets else self.sheet_items

tests/test_3_xlsx.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ def test_parse_xlsx_sheet_items(worksheet):
3232
assert "Taipei" in str(ws_items)
3333
assert "Bratislava" not in str(ws_items)
3434
assert "None:" in str(ws_items)
35+
assert "'None'," not in str(ws_items) # Tests whether empty cells were converted to "" strings and not "None"
3536
assert None in ws_items[0]
3637
assert len(ws_items) > 1
3738
assert len(ws_items) == 6

0 commit comments

Comments
 (0)