Skip to content

Commit

Permalink
#251 Support pathlib.Path as arguments to Xlsx2csv and Xlsx2csv.convert
Browse files Browse the repository at this point in the history
  • Loading branch information
dilshod committed Aug 27, 2024
1 parent bed9ef1 commit 007178d
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions xlsx2csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,11 @@ def convert(self, outfile, sheetid=1, sheetname=None):
os.makedirs(outfile)
elif os.path.isfile(outfile):
raise OutFileAlreadyExistsException("File " + str(outfile) + " already exists!")
elif hasattr(outfile, "open"):
if outfile.exists():
raise OutFileAlreadyExistsException("File " + str(outfile) + " already exists!")
outfile = outfile.open("w+", encoding=self.options['outputencoding'], newline="")

for s in self.workbook.sheets:
sheetname = s['name']
sheetstate = s['state']
Expand Down Expand Up @@ -307,6 +312,10 @@ def _convert(self, sheet_index, outfile):
else:
raise XlsxException("error: version of your python is not supported: " + str(sys.version_info) + "\n")
closefile = True
elif hasattr(outfile, "open"):
outfile = outfile.open("w+", encoding=self.options['outputencoding'], newline="")
closefile = True

try:
writer = csv.writer(outfile, quoting=self.options['quoting'], delimiter=self.options['delimiter'],
lineterminator=self.options['lineterminator'])
Expand Down

0 comments on commit 007178d

Please sign in to comment.