Can I define powerpoints or presentations in raw text?
Hi Guys : I w开发者_如何学运维anted to create a power point presentation using a raw text file, so that i can rapidly edit the file and see the results, gauranteed with uniform formatting. Basically, I'm talking about separating the data content from the presentation.
How can I do this ? Im thinking that maybe Latex could be a choice. I've also seen that there are API's for Powerpoint and open office presentations.
Powerpoint exposes it's API via COM - which makes it possible to do (almost) anything that you can do in the GUI in any programming language that supports COM. The difficulty is that the API changes between releases. One way to scope out the API is to use the macro recording facility to manually do one slide, and then translate that to your target language.
I've got some old (not tested recently) python code for Powerpoint 2003 that should give you an idea of what the code might look like depending on your layout needs.
from win32com.client import Dispatch
ppLayoutTitle = 1
ppLayoutText = 2
def writePresentation( fname, data ):
pptApp = Dispatch('Powerpoint.Application')
pres = pptApp.ActivePresentation
aw = pptApp.ActiveWindow
slides = pres.Slides
for item in data:
t1 = item[0]
t2 = item[1]
stype = item[2]
assert(stype in [ppLayoutTitle,ppLayoutText])
s = slides.Add( slides.Count, stype )
aw.View.GotoSlide(s.SlideIndex)
s.Shapes.Item(1).Select()
aw.Selection.ShapeRange.TextFrame.TextRange.Select()
aw.Selection.ShapeRange.TextFrame.TextRange.Characters(Start=1, Length=0).Select
tr = aw.Selection.TextRange
tr.Text = t1
s.Shapes.Item(2).Select()
aw.Selection.ShapeRange.TextFrame.TextRange.Select()
if stype == ppLayoutText:
aw.Selection.ShapeRange.TextFrame.TextRange.ParagraphFormat.Bullet.Visible = 0
aw.Selection.ShapeRange.TextFrame.TextRange.Characters(Start=1, Length=0).Select
tr = aw.Selection.TextRange
tr.Text = t2
slides.Range(slides.Count).Delete()
pres.SaveAs(fname)
Edit:
Openoffice (that can export to powerpoint) also ships with it's scripting API that could be used to solve similar problems.
If all you need is slides with titles and bulleted text, it's quite simple. Create a txt file that looks like this (use the TAB key in place of below):
Slide 1 Title
<tab>Bullet Level One Text
<tab><tab>Bullet Level Two Text
<tab>Back to Bullet Leven One again
Slide 2 Title
Slide 3 Title
<tab>More Bulleted text
<tab><tab>Tufte hates us by now
<tab><tab>But we don't care, do we?
Slide 4 Title
And so on. Save the file, start PowerPoint, choose the file open command, choose Outline or files of all types in the file open dialog box and select your TXT file. Done.
精彩评论