I have an excel spreadsheet with some complicated calculations implemented.
Is there a way I can feed the spreadsheet with input data, run the calculations and get the results from the python script level?
http://www.pythonexcels.com/2009/10/python-excel-mini-cookbook/
http://oreilly.com/catalog/pythonwin32/chapter/ch12.html
Driving Excel from Python in Windows
..doable using the win32 python API
Related
I am trying to develop a Python program for a task. The task is to find all routes in a state/county which are not reachable within 60 minutes from certain locations.
The task will take data (route info, speed limit, etc.) from excel. The excel data will be changed because there are many states/counties in USA/Canada.
I want to link the python code with excel such that we can get answers by clicking on the excel sheet.
Can you tell me how this can be done? Any ideas?
I'm pretty inexperienced with Power BI and Power Automate so apologies if there is a simple answer to this question (I couldn't find it at least).
I have a python script that takes data from some excel files, creates a few dataframes, and then produces an excel workbook with 3 sheets as the result. The script essentially uses pandas for the dataframe work and then xlsxwriter to produce the excel sheet. The input excel files are received via email daily.
We've just started using Power BI and Power Automate at work and I was able to create a flow that takes the input excel files directly from my inbox and pastes them into a work sharepoint. I would then run the python script manually.
However, I've recently been trying to automate running the python script in Power BI / Automate, given the success of the 1st flow. However, I have not found a solution that seems to work.
I've tried creating another flow that essentially starts with a trigger that activates when the input excel files are updated. I then input the code into Power BI as a dataset with an action in the flow to update this Power BI dataset. The flow is successful but doesn't produce the output excel file.
Essentially, I want the python script to run whenever the input files in the sharepoint are updated (result of the 1st flow) but I'm confused as the best route to go down. It seems I could generate each worksheet as a table in Power BI and maybe export those into an excel workbook but I haven't had any success.
To my knowledge there is no direct way to do what you are asking. But I think there are multiple workarounds so here are my recommendations:
(Recommmended solution) I love python, but Power BI is built to injest data via Power Query. I have found that Power Query can do similar tasks to Python, in regards to data cleansing. Here is quick start guide on Power Query. So my recommended approach is continue to use Power Automate to push excel files to SharePoint. Then utilize PowerQuery to pull the data into Power BI and format it the way you want. If you are publishing the PowerBI dashboard to the PowerBI app you can schedule up to 8 refreshes a day of your data. I think it's also possible to use Power Automate to push refreshes of the data as well.
Continue with current approach utilizing Power Automate to pull excel files from inbox to SharePoint but use Windows scheduler to run your python script on a recurring schedule..
Is it possible, When exporting a dataset from SPSS to Excel, to control the name of the worksheet the data is being saved into ? The "SAVE TRANSLATE OUTFILE" command does not allow for this. I have SPSS 21, with Python installed (although I am fairly new to Python...)
Yes. See this weblink on IBM website for details.
get file="C:\Program Files\IBM\SPSS\Statistics\23\Samples\English\Employee data.sav".
SAVE TRANSLATE
/TYPE=ODBC
/CONNECT='DSN=Excel Files;DBQ=C:\Daten\Temp\EmployeeDataExcelExport.xlsx;'
/ENCRYPTED
/MISSING=IGNORE
/REPLACE
/TABLE='EmployeeData'.
EDIT:
The syntax provided in the link on IBM website does NOT work for me however the below does:
save translate
/connect="dsn=excel files;dbq=C:\Temp\EmployeeDataExcelExport.xls;driverid=790;maxbuffersize=2048;pagetimeout=5;"
/table="EmployeeData"
/type=odbc /map /replace.
SAVE TRANSLATE relies on ODBC drivers, which means that your Statistics and Office bitness has to match - 64-bit Statistics with 32-bit Office won't work. Otherwise, you can write to an Excel file with SAVE TRANSLATE and then use VBA automation via a Basic script in Statistics to rename the sheet. There is a Basic module available from the SPSS Community website that writes output tables to an Excel file that does some sheet renaming that you could adapt for your purposes.
You can find the module here
https://www.ibm.com/developerworks/community/files/app?lang=en#/file/8e0dfcb6-aa57-4639-a20e-1780010cfe83
Is there anyway we can call an excel addin using python?
I would like to call a user-defined add-in which is present in excel using a python program. I need a freeware I think pyxll requires license.
You can try xlwings if you like to use python inside your excel.
Or try to dispatch excel with win32com
excel = win32com.client.gencache.EnsureDispatch ("Excel.Application")
I think that you'd have to save your add-in as vba project (How to Use Your Excel Add-In Functions in VBA.
Generally nearly everything that can be done via VBA could be done with python and dispatched excel, so VBA Object Model reference is a good documentation on it.
I know python can manipulate Excel data but I don't know whether it can generate charts in it.
Does such a library exist?
Excel is an OLE Automation server (which is built on COM), which means it has a discoverable interface that makes it possible to automate it from any tool that understands COM. Providing you're on Windows, Python is one of many such tools and you already have (or can easily obtain) the library you need: it's PythonCom.
See this snippet for an example of how a Python script uses the library to talk to Excel. It doesn't seem to explicitly work with charts, so you'll need to figure that out for yourself: try using the Macro Recorder to get an idea (in VBA) of how to achieve what you want, then translate that into Python.
If you're not running on Windows, then you're going to need code that understands the Excel file format, which is fairly achievable in the new xlsx/xlsm XML-based world (available from Excel 2007 onwards) and rather more difficult in the old binary xls form.