PydPiper / pylightxl

A light weight, zero dependency, minimal functionality excel read/writer python library
https://pylightxl.readthedocs.io
MIT License
302 stars 47 forks source link

Handle filenames in the same way for csv and excel #94

Open LeonardVertighel opened 1 year ago

LeonardVertighel commented 1 year ago

Pylightxl Version: 1.61 Python Version: 3.9.2 Operative system: Linux Debian 11.7

Summary of Feature: I use pylightxl to manage excel and csv files in the same way, but I have found that the writexl and writecsv functions work differently on the filename. In the writexl function I can indicate the file extension ('Test.xlsx') and the file on disk will be 'Test.xlsx', while in the witecsv function if I indicate the extension ('Test.csv') the file name on disk will be 'Test.csv_sheet1.csv' My opinion is that the functions should behave the same way

NOTE: in the example at https://pylightxl.readthedocs.io/en/latest/quickstart.html#read-write-csv-file it is indicated to use new.csv as the filename

Traceback: In writexl i can write 'Test.xlsx' and the filename on disk became 'Test.xlsx' xl.writexl(db=workbook, fn='Test.xlsx', ws='sheet1') In writecsv ican write 'Test.csv' and the filename on disk became 'Test.csv_sheet1.csv' xl.writecsv(db=workbook, fn='Test.csv', ws='sheet1', delimiter=';')

Suggestion for fix: Use regular expression to delete the extension if it is present in the input parameter: fn = re.sub(".csv$","",fn, flags=re.IGNORECASE)