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.
Related
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 have a couple of Python scripts that are acting funny on my computer. A couple of colleagues use the same script and don't have any issues. Both scripts take a .csv as an input, make some transformations and then open a new .csv or Excel file.
One of them will open the new file, but it won't show up in the working directory; when you go to save the open file then it says the file already exists in the working directory. It allows you to replace it, but even after this is doesn't show up. A picture of that is below.
Here is the saving script for that:
result.to_csv('TypeMapping_filled_{}.csv'.format(str(datetime.date.today())), index=None, header=True)
os.startfile('TypeMapping_filled_{}.csv'.format(str(datetime.date.today())))
The other one will run the script, but the file won't open or show up in the directory.
Here is the saving script for that:
styled_output.to_excel(f'REFORMATTED_{file_name[:(len(file_name)-4)]}.xlsx', index=None, header=True, engine='openpyxl')
Any thoughts on what might be going on?
I have written a code which opens an excel file via excel wings library and instruct such file to run a macro within the excel file itself. The macro within the file consists of a series of Refreshes which happen on another excel workbook through some excel add ins.
The issue is that when I open the excel file and run the VBA macro from there no issues arise. However, when I use Python to run the process I get a run time error 1004 in the VBA macro, which reads macro not available in the current workbook, despite the macro obviously being there. I believe this is because, for some reason, when Python launches Excel the add ins may not automatically load.
I have long looked for a solution around but nothing satisfactory yet. Any help is massively appreciated!
I'm new to Pandas and I was beginning to run a simple code to work with this CSV file I downloaded from the government portal. Here's my code -
import pandas as pd
df = pd.read_excel(r'C:\Users\ADMIN\Desktop\Abhishek')
print(df.head)
The path is correct and it didn't work without adding the r at the beginning so I used that. However, this code results in these errors and I'm not sure how to handle any of them.
I've opened the file on Excel and I don't think there's any problem with it. What am I doing wrong?
Python doesn't have permission to open the file. Run your interpreter as administrator, or adjust permissions.
Right click your python shell and select "run as administrator".
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.