After read and write an excel file using python modules xlrd and xlwt, my excel file is corrupted. I faced following prompt while opening using excel 2016. But, the file is opening perfectly in google sheets...
The error excel 2016 throwing is
"Can't open file beacuse the file format or file extension is not valid"
As I mentioned in my above comment, the xlwt package (https://pypi.org/project/xlwt/) is only capable of writing to xls format.
Either change the extension of your file and try it, or change your code to save it as xls format.
I can't see your code but imagine it would look something like this:
wb.save('example.xlsx')
when it should be
wb.save('example.xls')
Related
I'm using heroku with streamlit to do excel automations. But I need to execute the excel formulas so I can get the values computed by them, and to do so I would need to open the excel file. As it is an RPA, I don't want to open the excel file myself, manually, I want the code to open it for me inside the system and execute the formulas, so the code opens the sheet with pandas or openpyxl and get the values provided by the formulas. As heroku runs on linux, OS is not an option. I've tried xlwings a long time ago and it did not work as well, but I'll study it and see if it works, but if you guys have some other recommendation for me, that works better than xlwings (or even something about xlwings usage), it would be really helpfull!
Thanks in advance!
I have already tried to use pandas and openpyxl data_only=True to get the values computed by formulas, but both only work once the excel file has been opened manually, executing all formulae. I want to simulate the manual opening of the excel file inside heroku, but without literally opening it, so formulas inside the file are executed.
My Python code properly writes to Excel using the pandas pd.ExcelWriter function. The challenge I am having is that I am saving the file to a OneDrive directory and it won't let me open the file in Excel once the code is executed unless I close Python. Effectively, the Excel file is considered still be used by Python and therefore cannot get synced in OneDrive.
Any suggestions on how to deal with this?
I am writing a dataframe to csv, but I am unable to view or access the file from file explorer. Any suggestions on how to access the file directly from file explorer?
I am using pandas functions "to_csv" and "read_csv" in Jupyter Notebook. I am successful in writing and reading from the csv file, which indicates the command is working.
However, the csv file is not present in File Explorer.
I am a py script that writes data into excel file. I am running the latter script on VM that sometimes crashes and if at that moment py script was writing data to excel, it corrupts the excel file.
Current solution to fix corrupt files is to manually 'Restore Previous Version' from file properties.
However I would like to do this task with python. Is there any solution for this?
You can save a copy of the excel file before manipulating it. If your script crashes because of an exception then you can catch it and then restore the file. If it crashes because of something like a memory error then you still have the copy of the file as a backup.
I am trying to use xlwt to create a output file (in .xlsx format) with multiple tabs. The version number of my Python is 2.7, and I am using Aptana Studio 3 as IDE.
I've used the xlwt package before, with the same environment, to carry out the same task. It worked well. But this time, it works well at first, then suddenly, the output file became faulty that cannot be opened by MS Excel.
Here is a clue that might be helpful. My Aptana Studio 3 decide to open .xlsx in its own editor rather than start MS Excel. Although this happens before the problem, I am wondering if it is related.
The file looks normal when it is opened in Aptana3, but when I closed it, and open it with MS Excel, an error pops up:"Excel cannot open the file "output.xlsx" because the file format or file extension is not valid. Verify that the file has not been corrupted and that the file extension matches the format of the file."
May I know how I can get over this? Any suggestions are welcome. Thanks.
The xlwt module cannot create .xlsx files. It is a writer for .xls files.
The warning is due to a feature in newer versions of Excel called "extension hardening" which means that the file extension has to match the file type.
If you change the output file extension in your program to .xls the warning should go away and Excel will read the file.