-
-
Notifications
You must be signed in to change notification settings - Fork 506
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Save no longer allows non-Excel formats in version 0.23.1 #1569
Comments
Was this previously giving you a tab-delimited Text file? |
Yes. I have been using it for about 20 months, and it was working perfectly until I updated to 0.23.1 |
yes, 0.23.1 added support for the Excel file formats, and ignored the non-Excel file formats for now. It should be easy to add. |
Thanks |
Actually, can you post a fully self-contained example of what you're doing/achieving? I tried the following with 0.22.3, which just gives me an Excel file with a import xlwings as xw
wb = xw.Book()
wb.save('YYY.txt') One way to export to CSV would be: import xlwings as xw
import csv
sheet = xw.books.active.sheets.active
with open('mycsv.csv', 'w') as csvfile:
writer = csv.writer(csvfile)
writer.writerows(sheet.used_range.value) |
Based on what your comments, below I did a little further research. This portion of my code causes a file to be downloaded from a central system. The file automatically appears loaded in Excel on my system, and then I save it using activeBook.save. However, I was not aware that the file structure that I receive is actually tab-delimited text (.txt). I found that when I go to File/Save As in Excel, the file format is noted as Text (Tab Delimited) (*.txt). So when I save it as a .txt, it is already in that format and therefore is saved in that format, regardless of the filename I choose. It appears that 0.22.3 actually does not do any conversion at all. A new book is saved as .xls, and an existing book is saved as whatever format it was when it was loaded into Excel. When 0.23.1 was implemented, it altered the save routine such that using the .txt extension is no longer recognized and therefore the Python script fails. Rewriting my code to use csv would not be my most preferred option. I am happy at this time to stay on 0.22.3 until such time as the kinks in the new save routine are ironed out, hoping of course that saving to .txt will be implemented along with other formats. For reference, here is the code snippet and a sample file:
|
Ok that explains the behavior then. Out of curiosity, why would you even need Excel to change a pure text file? |
The download process from the host creates the file with a name ending in .xls and then automatically opens it in Excel.
System is old and maintenance is a pain. Easier to use Python to just save the file as text then load it into the app(s) as required.
From: Felix Zumstein ***@***.***>
Sent: Thursday, April 29, 2021 4:24 PM
To: xlwings/xlwings ***@***.***>
Cc: Doug Lee ***@***.***>; Author ***@***.***>
Subject: Re: [xlwings/xlwings] Save no longer allows non-Excel formats in version 0.23.1 (#1569)
Ok that explains the behavior then. Out of curiosity, why would you even need Excel to change a pure text file?
-
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub<https://can01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fxlwings%2Fxlwings%2Fissues%2F1569%23issuecomment-829570626&data=04%7C01%7Cdougl%40fernlea.com%7Cf8aa4dd90b934cefcb0308d90b4cad1e%7C61a302a80be04000afb48f6dbe28dd3d%7C0%7C0%7C637553246211480473%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=9D6Vg2LuwRH1tEjN6mfWJOSCvDqkvfofw41yGQf6tKw%3D&reserved=0>, or unsubscribe<https://can01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAMZCUIMI4PH6JN5IVGY4Q7LTLG54XANCNFSM43S73ZFA&data=04%7C01%7Cdougl%40fernlea.com%7Cf8aa4dd90b934cefcb0308d90b4cad1e%7C61a302a80be04000afb48f6dbe28dd3d%7C0%7C0%7C637553246211480473%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=X7DJxDoxcXfQ187mYGDI2%2BF80Hk%2FOM1vDUn7ldOg8A8%3D&reserved=0>.
CONFIDENTIALITY NOTICE: This e-mail message and attachments, if any, are sent by a Third Party Administrator for the sole use of the intended recipient(s). It may contain information that is privileged and/or confidential. If you are not the intended recipient, please notify the sender immediately by reply email and destroy this communication. Thank You.
|
Windows 10 Enterprise 64-bit
Python 3.7.4
xlwings 0.23.1
Excel 2019
Prior to version 0.23.1, I could save a book in alternate formats, such as '.txt' just by specifiying the appropriate filename/extention. That now gives a "KeyError: '.txt'" This was working perfectly until I updated to 0.23.1.
Sample Code:
activeBook = books('DL2SALES.XLS')
activeBook.save(path + fileName+'.txt')
Traceback:
File "c:/Users/dougl/Documents/Python/Fernlea/Costing Data to Excel/Main21.py", line 513, in
if Flags['Items']: performProcess(ProcessList, 'Item Master')
File "c:/Users/dougl/Documents/Python/Fernlea/Costing Data to Excel/Main21.py", line 162, in performProcess
saveExcelFile(currentAction[1], basePath, basePath1)
File "c:/Users/dougl/Documents/Python/Fernlea/Costing Data to Excel/Main21.py", line 420, in saveExcelFile
activeBook.save(path + fileName+'.txt')
File "C:\Program Files\Python37\lib\site-packages\xlwings\main.py", line 740, in save
self.impl.save(path)
File "C:\Program Files\Python37\lib\site-packages\xlwings_xlwindows.py", line 533, in save
file_format = ext_to_file_format[target_ext]
KeyError: '.txt'
EDIT: downgrading to 0.22.3 has eliminated the issue.
The text was updated successfully, but these errors were encountered: