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.
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.
Don't know if this sort of question belongs to this forum, but I will give it a shot:
I have started using bokeh as an alternative to be able to share Python-generated data and plots in between my colleagues (who don't necessarily have Python, or any knowledge of the language for that matter).
Since some of the data I am using could potentially be proprietary, I would like to now how the data is actually stored when outputted from Python as a html-file?
Moreover, will anyone outside of my organization be able to get a hold of the data that the file is built up on? Meaning, is the person double-clicking on the .html-file, running it through her Chrome/Explorer the only one that can access the data that is generated in the plots etc., or could someone potentailly snoop the data externally?
Using Python code as in:
from bokeh.io import output_file
output_file('data.html', title="test data")
Thank you, and hope it's not a too a lame/bad question for this forum.
When you set the output_file and save the HTML file it is all done so locally; I don't believe it is shared to a cloud service (like plotly).
The HTML file will contain the original data used to produce the plots. If that concerns you, you can save snapshots of the plots with the save button on the toolbar.
I made a sheet with a graph using python and openpyxl. Later on in the code I add some extra cells that I would also like to see in the graph. Is there a way that I can change the range of cell that the graph is using, or maybe there is another library that lets me do this?
Example:
my graph initially uses columns A1:B10, then I want to update it to use A1:D10
Currently I am deleting the sheet, and recreating it, writing back the values and making the graph again, the problem is that this is a big process that takes days, and there will be a point that rewriting the sheet will take some time.
At the moment it is not possible to preserve charts in existing files. With rewrite in version 2.3 of openpyxl the groundwork has been laid that will make this possible. When it happens will depend on the resources available to do the work. Pull requests gladly accepted.
In the meantime you might be able find a workaround by writing macros to create the charts for you because macros are preserved. A bit clumsy but should work.
Make sure that you are using version 2.3 or higher when working on charts as the API has changed slightly.
I have a script to format a bunch of data and then push it into excel, where I can easily scrub the broken data, and do a bit more analysis.
As part of this I'm pushing quite a lot of data to excel, and want excel to do some of the legwork, so I'm putting a certain number of formulae into the sheet.
Most of these ("=AVERAGE(...)" "=A1+3" etc) work absolutely fine, but when I add the standard deviation ("=STDEV.P(...)" I get a name error when I open in excel 2013.
If I click in the cell within excel and hit (i.e. don't change anything within the cell), the cell re-calculates without the name error, so I'm a bit confused.
Is there anything extra that needs to be done to get this to work?
Has anyone else had any experience of this?
Thanks,
Will
--
I've investigated further and this is the issue:
When saving the formula "STDEV.P" openpyxl saves it as:
"=_xludf.STDEV.P(...)"
which is correct for many formula, but not this one.
The result should be:
"=_xlfn.STDEV.P(...)"
When I explicitly change the function to the latter, it works as expected.
I'll file a bug report, so hopefully this is done automatically in the future.
I suspect that there might be a subtle difference in what you think you need to write as the formula and what is actually required. openpyxl itself does nothing with the formula, not even check it. You can investigate this by comparing two files (one from openpyxl, one from Excel) with ostensibly the same formula. The difference might be simple – using "." for decimals and "," as a separator between values even if English isn't the language – or it could be that an additional feature is required: Microsoft has continued to extend the specification over the years.
Once you have some pointers please submit a bug report on the openpyxl issue tracker.