Currently I'm working on Python to automate a powerpoint file. I'm using win32com.client to access the various objects needed. However I haven't been able to find any documentation on chart objects. can someone point me in the right direction.
import win32com.client
PPTApplication = win32com.client.Dispatch("PowerPoint.Application")
PPTApplication.Visible = True
PPTFile = PPTApplication.Presentations.Open("D:\test.pptx")
x=PPTFile.Slides(1).Shapes("Chart1").Chart.ChartData.Workbook.Sheets(1).Range("A1","C13").Value
The code above allows me to access the data for chart1.
How do I access the format axis options????
Or where can I find the documentation for the same.
The PowerPoint Chart object API is documented here:
https://msdn.microsoft.com/EN-US/library/office/ff746468.aspx
The direction you'll want to head is Chart.Axes(), perhaps Chart.Axes(xlValue).
Once you have the axis you want, you have the properties and methods listed here available to you:
https://msdn.microsoft.com/EN-US/library/office/ff745187.aspx
In my experience, it sometimes takes some digging to come up with the path to the right attribute, but that's the general procedure.
Usually when I don't find what I'm looking for I search on 'vba powerpoint chart font color' or whatever specific call I'm looking for and the example VBA code shows the "path" through the object hierarchy to the property I need.
Related
I am trying to align text in a cell inside of an excel file that was created with xlwings. I am aware that there isn't a top level function in xlwings to achieve that. However, in the documentation, it states that .api can be used to access the pywin32 (on windows) to achieve that goal and in the documentation for pywin32 there is a method called SetTextAlign.
My problem is that I cannot figure out how to call it or what arguments to pass into it. A good bit of info can be found here: http://timgolden.me.uk/pywin32-docs/PyCDC__SetTextAlign_meth.html
but that only helps me a tiny bit.
So, for example, my code could be:
self.sheet['A1'].value = 'test'
self.sheet['A1'].font.api ... # code here to set the alignment to center
Would be super appreciated if someone could help!
self.sheet['A1'].api.HorizontalAlignment = xlwings.constants.HAlign.xlHAlignCenter
Alignment is not a font property, but a Range property. A cell ('A1') is a Range.
You can find the Excel API here.
The PyCDC documentation you found is some internal Windows API, it is irrelevant for Excel features.
I recently started working on my very first dashboard application using dash.
The tutorials are comprehensible, however, I have a hard time handling the front end details because I cannot find an API reference. Specifically, each element accepts a style argument that let's us modify some CSS details, like text alignment, fonts etc. I have seen some examples in the tutorials but I would love to have an exhaustive list of everything I can pass there.
As an example, I want to create a table but the columns are too close together. I need to control the spacing between them and I imagine there should be an argument like padding, spacing, borderSize... you get the point. Where can I find these details?
It could be possible to edit some styling by passing some keywords to the Dash component. It depends on the component itself.
For example, if you are using DataTable from dash-table-experiment:
import dash_table_experiments as dt
help(dt.DataTable)
you can see that the API of this component allows you to set things like column_widths (list; optional) and min_width (number; optional).
If you need some more complex styling (e.g. a yellow background with linear gradient for all even table cells) I'm afraid you'll have to know some CSS.
A few additional resources:
Currently the Dash styleguide is based on the Skeleton CSS framework
Each dcc.Graph is composed by a figure and a layout. Here is the plotly.js figure reference
For things like showing/hiding legends, traces, etc, have a look at the plotly.js configuration options
For HTML: https://github.com/plotly/dash-html-components
For component: https://github.com/plotly/dash-core-components
Seems the dash project didn't create the user-friendly API document (I guess it was related to their business strategy).
The only way to get the help is the dash community and git-code project.
if you want help with python objects in dash then just use:
help(html.Div)
to get a list of argument parameters.
If you want to know what can be placed in the style parameter the answer is any and all css can be generated. You can customize the look anyway you want here is the syntax...
style={
'border':'1px solid #333',
'margin':'10px',
'padding':'10px',
'background-color':'#888',
'position':'absolute',
},
The style parameter excepts a dictionary object. In order for your CSS to be rendered it needs to be in the syntax above, which will create a python dictionary object.
I am trying to use GTK and libchamplain to display a map from local map data. The application is to be run on computers with no internet connection.
After taking a look at the mapbox.py example it seems like one should replace the NetworkTileSource source with FileTileSource. So I used the minimal.py example to work with FileTileSource:
widget = GtkChamplain.Embed()
widget.set_size_request(640, 480)
tile_source = Champlain.FileTileSource.new_full(
ID,
NAME,
LICENSE_TEXT,
LICENSE_URL,
MIN_ZOOM,
MAX_ZOOM,
TILE_SIZE,
Champlain.MapProjection.MERCATOR,
Champlain.ImageRenderer())
tile_source.load_map_data("map.osm")
widget.get_view().set_map_source(tile_source)
Unfortunately, when running the application, the map is not being displayed, and I receive the following error message:
(minimal.py:26308): libchamplain-WARNING **: NULL pixbuf
Based on some C examples (one, two), I assume that there is a so-called renderer missing, called Memphis, which is C only. It seems like Champlain's ImageRenderer, despite its similar name, is not the right tool for this.
So my question is how I would continue at this point. There are quite a few OSM renderers besides Memphis, probably some written in Python as well, but which one(s) would integrate well with Champlain?
It doesn't have to be be OSM, either. A collection of pre-rendered PNG would be fine with me, too. It's just that the FileTileSource documentation specifically mentions "Loads the OpenStreetMap XML file at the given path", which is why I assume better support for OSM.
Any help is much appreciated.
I managed to do it in a very simplistic way: just organize your tiles respecting the #z#/#x/#y# logic as described in the docs, then don't change anything in that mapbox.py example except the URI. your case, for a file structure on the /tmp directory could look like:
MAX_ZOOM,
TILE_SIZE,
Champlain.MapProjection.MERCATOR,
"file:///tmp/tiles-#Z#/#X#/#Y#.png",
#"https://a.tiles.mapbox.com/v4/mapbox.streets/#Z#/#X#/#Y#.png?access_token=" + ACCESS_TOKEN,
Champlain.ImageRenderer())
still according to the docs, the FileTileSource is meant for using a single osm file. I'm not so sure how that works, I didn't yet try it.
I'm using appscript to create an InDesign document from Database data, but I can't seem to figure out how to set the contents of the objects in my page. In older versions of ID (CS4 and earlier, if i'm correct) I could get the object with script label foo by calling spread.page_items['foo']. However, this does not seem to work anymore. spread.page_items.ID(<foo_id>).label.get() does show foo, so the script label is set correctly.
The Adobe documentation speaks of a label property, however I haven't yet figured out how to use that property to correctly select the right object.
If there is a way to obtain an object's ID easily, that might also do the trick.
I managed to solve this after finding this article about references in appscript. I had to use a filter, like so: spread.page_items[its.label == 'foo'].
Also, as suggested by Youngware below, the script labels support is indeed replaced by layer names.
I use win32com to handle office document in Python.
There is no way to know what method does an Object have in win32com.
(In general, we can fetch properties or methods by DIR(OBJ) in Python )
So, if we want to know what properties or methods does my powerpoint document have , just go to look up MSDN
however , I have a powerpoint file contains lots of object.
but i don't know what name or type is it.
for example ,when i want to access text in powerpoint i can use Presentation.Slide.Textframe.TextRange.Text to access it.
How about formula??? if i want to access it?
Is there anyway when I click mouse on the object in my powerpoint file, and then show what type of the object is?
Thanks you all in advance.
For your first question you want to use the MakePy Utility to create early-bound objects so you can introspect them (ie. press tab and look at all the methods in your IDE). It will cut down searching on MSDN by 95%
Easiest way to do this is go to PythonWin (installed with win32com) and go to Tools > COM Makepy Utility and select the COM library you want to use (in your case it is something like 'Microsoft PowerPoint 14.0 Object Library'). Let this run and you are all set. This is also described here.
For your second question, as David pointed out most of the objects are Shapes. Once you run the MakePy Utility you will be able to see the entire PP Object Model. A quick search helped me find how to get the active shape that is selected by clicking on it.
import win32com.client
app = win32com.client.Dispatch("PowerPoint.Application")
selectedShape = app.ActiveWindow.Selection.ShapeRange(1)
You can now play around with selectedShape to find out everything you need to know about it.