I am writing an Excel Macro that parses a user's selection and uses the data to create a SQL database table. I'm using DataNitro to fire off the scripts straight from Excel, but need help feeding the Excel selected values into my python script.
I know that DataNitro lets you access and edit Cells straight from Python, but all the examples they provide are hard-coded ( eg CellRange("A1:B5") ). Is there a way to get a selected range, similar to VBA's Selection.Address method?
Thanks!
You can use the active_cell command to get the selected cell: https://datanitro.com/docs/cell.html?highlight=active_cell#active_cell
There's currently no way to get a selected range, but we do plan to add it in the future.
[Source: I'm one of the developers.]
Related
I am using Python and gspread to upload local .csv data to a google SpreadsheetA.
I have a separate google SpreadsheetB that uses =IMPORTRANGE to import the data from SpreadsheetA and create a pivot table and corresponding chart (both located on SpreadsheetB).
If I were to manually adjust any data in SpreadsheetA (e.g., alter value of any cell, add a value to an empty cell, etc), then the data in SpreadsheetB—with its corresponding pivot table and chart—update dynamically with the new data from SpreadsheetA.
However, when SpreadsheetA is updated with new data programmatically via Python, IMPORTRANGE in SpreadsheetB does not capture the new data.
Any ideas as to why this happens and how I might be able to fix?
Both Sheet A and B show the same number of rows. I am a bit confused with your IMPORTRANGE() formula though, why the ampersand?
=IMPORTRANGE("https://docs.google.com/spreadsheets/d/16DyWC8rsQB1ThpLiQh0p5xH9CYK2cPqbPH547ybw2Fo/edit#gid=1875728384",""&"TestgAPI!A:J")
I changed to this:
=IMPORTRANGE("https://docs.google.com/spreadsheets/d/16DyWC8rsQB1ThpLiQh0p5xH9CYK2cPqbPH547ybw2Fo/edit#gid=1875728384","TestgAPI!A:J")
Although probably not the ideal, my solution to this was to use gspread to add a new worksheet to spreadsheetA, which somehow manages to kickstart importrange() in SpreadsheetB.
I would still love to see a cleaner solution, if anyone knows of one—but this has continued to work since implementing a week ago.
For my python script, there is one missing simple trick when I want to take data from Excel with Python win32com.
I just want to know how to get selected cells information, e.g. col/row for my python script. For example I could specify the range as shown below, but I simply cannot do the same thing to the selected/active cells.
ws.Range("B1:AM167").CopyPicture()
Does someone help me with this?
I am quite new to win32, so I still do not know how to find correct method/property etc...
Try Application.Selection.
The returned object type depends on the current selection (for
example, if a cell is selected, this property returns a Range object).
The Selection property returns Nothing if nothing is selected.
I've been looking for ages to find a suitable module to interact with excel, which needs to do the following:
Check a column of cells for an "incorrect" value and change it
Check for empty cells, and if so, replace it
Check a cell value is consistent with the contents of another cell(for example, if called Datasheet, the code in another cell = DS)and if not, change it.
I've looked at openpxyl but I am running Python 3 and I can only seem to find it working for 2.
I've seen a few others but they seem to be mainly focusing creating a new spreadsheet and simple writing/reading.
The Pandas library is amazing to work with excel files. It can read excel files easily and you then have access to a lot of tools. You can do all the operations you mentionned above. You can also save your result in the excel format
When selecting a data source for a graph in Excel, you can specify how the graph should treat empty cells in your data set (treat as zero, connect with next data point, leave gap).
The option to set this behavior is available in xlsxwriter with chart.show_blanks_as(), but I can't find it in openpyxl. If anyone knows where to find it or can confirm that it's not present, I'd appreciate it.
Asked the dev about it -
There is a dispBlanksAs property of the ChartContainer but this currently isn't accessible to client code.
I looked through the source some more using that answer to guide me. The option is definitely in there, but you'd have to modify source and build locally to get at it.
So no, it's not accessible at this time.
I am attempting to add an Excel like filtering option to a program that is processing 3 xml files and optionally an xls file. One of the problems I am running into is finding good examples of applying multiple filters at once. I understand that Filter.Chain allows for multiple "pre-built" filters to be applied at once, the main trouble is being able to dynamically create the filters then applying them. For example, one of the things being looked at by the program is vehicle makes such as Honda, Ford, etc and I would like to be able to select which makes I want to see in the ObjectListView.
Due to the amount of code in use it is hosted at pastebin:
Main Gui
Worker Script
Input Panel
Primary Output
Secondary Output
What I am hoping to find are examples of how I would be able to add an Excel like filtering. Currently I have a menu option set that opens a MultiChoiceDialog window which provides a list of options, but I am unable to find a good pythonic way of taking the selections and applying them as a filter or series of filters.
Thanks in advance.
It appears that you are reading an Excel file into your ObjectListView widget. I think it would be easier to load the data into a sqlite database and then use SQL commands to do your filtering. I prefer using SQLAlchemy. That way I can create a class that represents the data that I can use both for SQLAlchemy and for my ObjectListView widget.
You can read about some of this sort of thing in the following articles:
http://www.blog.pythonlibrary.org/2012/06/04/wxpython-and-sqlalchemy-loading-random-sqlite-databases-for-viewing/
http://www.blog.pythonlibrary.org/2011/11/10/wxpython-and-sqlalchemy-an-intro-to-mvc-and-crud/