问题
I am trying to export an active page to an existing PowerPoint presentation. I know how to do this from the title bar, but I would like to incorporate this into the IronPython code I am writing so I can do several slides at once.
Thanks, Joseph
回答1:
This will open up powerpoint and export one visualisation per page:
from System.IO import *
from Spotfire.Dxp.Application.Visuals import VisualContent
from System.Drawing import Bitmap, Graphics, Rectangle, Point
import clr
clr.AddReference("Microsoft.Office.Interop.PowerPoint")
import Microsoft.Office.Interop.PowerPoint as PowerPoint
powerpoint = PowerPoint.ApplicationClass()
powerpoint.Visible = True
pres=powerpoint.Presentations.Add()
slideCounter = 1
for visual in Document.ActivePageReference.Visuals:
#print visual.Title
#export graphic to temp file
vc = visual.As[VisualContent]()
bm = Bitmap(2000, 1200)
g = Graphics.FromImage(bm)
r = Rectangle(Point(0,0), bm.Size)
vc.Render(g, r)
file = Path.GetTempFileName()
bm.Save(file)
#pp setup
slide=pres.Slides.Add(slideCounter, PowerPoint.PpSlideLayout.ppLayoutTitleOnly)
slideCounter = slideCounter+1
slide.Shapes.AddPicture((file), False, True, 30, 60, 650, 400)
title=slide.Shapes.Title
txt=slide.Shapes.AddTextBox(1,10,500,500,100)
title.Top=0.1
obj=slide.Shapes.Title.TextFrame.TextRange
obj.Font.Size=24
You can loop through pages with:
for page in Document.Pages:
Document.ActivePageReference=page
Adjusted from code found here: https://tibbr.tibcommunity.com/tibbr/#!/messages/69369
回答2:
They are in Spotfire API's. Each page has a bunch of visualization. Look at the snippet below and you may get an idea.
foreach (Spotfire.Dxp.Application.Page page in SpotfireDocument.Pages)
allVisuals.AddRange(page.Visuals);
// in my case SpotfireDocument extends {Spotfire.Dxp.Application.Document}
But, anybody here knows how to get visual of the entire active page? The above method will give snap of sub-visual on active page, but not the entire page itself.
来源:https://stackoverflow.com/questions/31731159/script-to-export-spotfire-graphic-to-powerpoint