Jump to content

exporting images to powerpoint using ironpython


Yacine El Gharbi

Recommended Posts

Hi! I'm working on exporting visualizations from Spotfire to a ppt file using Ironpython. I used the following script and it's actually working. Although I'm trying to export those images to an existing ppt template and in reserved image fields. I hope you can help me do the necessary modifications on my script. Thanks!

from System.Drawing import Bitmap, Graphics, Rectangle, Pointfrom Spotfire.Dxp.Application.Visuals import VisualContentfrom System.IO import Pathimport clr clr.AddReference("Microsoft.Office.Interop.PowerPoint")import Microsoft.Office.Interop.PowerPoint as PowerPoint##################### Powerpoint setuppowerpoint = PowerPoint.ApplicationClass()powerpoint.Visible = Truepres=powerpoint.Presentations.Add()slideCounter = 1##################### image properties obtained from properties entries (can be hard coded)width = int(Document.Properties["myWidth"])height = int(Document.Properties["myHeight"])################### obtain_image() - takes in 1 parameter (visualization handle)def obtain_image(viz):#file = "c:\tmp\test.jpg" # 'tmp' directory needs to exist file = Path.GetTempFileName()  # obtain image vc = viz.As[VisualContent]() bm = Bitmap(width, height) g = Graphics.FromImage(bm) r = Rectangle(Point(0,0), bm.Size) vc.Render(g, r) bm.Save(file) addToSlide(file)################### # addToSlide - takes 1 parameter (filename)def addToSlide(file): global slideCounter #pp setup slide=pres.Slides.Add(slideCounter, PowerPoint.PpSlideLayout.ppLayoutBlank) slideCounter = slideCounter+1 slide.Shapes.AddPicture((file), False, True, Left=0, Top=10, Width=-1, Height=-1)################## # main part of programfor page in Document.Pages: print page.Title for visual in page.Visuals: if (visual.TypeId.ToString().find("Html") < 0): print "t",visual.Title,": ", visual.TypeId.ToString() obtain_image(visual)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...