Skip to content

Instantly share code, notes, and snippets.

@informationsea
Created February 27, 2016 08:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save informationsea/aee812b46fa1d8445f0c to your computer and use it in GitHub Desktop.
Save informationsea/aee812b46fa1d8445f0c to your computer and use it in GitHub Desktop.
Power Point Slide Show Generation Test
@Grab(group='org.apache.poi', module='poi', version='3.13')
@Grab(group='org.apache.poi', module='poi-ooxml', version='3.13')
@GrabExclude(group = 'stax', module = 'stax-api')
@Grab(group='org.apache.poi', module='poi-scratchpad', version='3.13')
import org.apache.poi.sl.usermodel.ShapeType
import org.apache.poi.sl.usermodel.TextParagraph
import org.apache.poi.sl.usermodel.VerticalAlignment
import org.apache.poi.xslf.usermodel.XMLSlideShow
import java.awt.Color
import java.awt.Rectangle;
def slideShow = new XMLSlideShow()
println slideShow.slideMasters
// create Rectangle
def slide = slideShow.createSlide()
for (i in [0, 10, 20, 30, 45, 60]) {
def autoShape = slide.createAutoShape()
autoShape.setShapeType(ShapeType.RECT)
autoShape.setAnchor(new Rectangle(10, 40, 200, 100))
autoShape.setLineColor(Color.BLACK)
autoShape.setLineWidth(1)
autoShape.setText("Rectangle")
autoShape.setHorizontalCentered(true)
autoShape.setRotation(i);
}
def autoShape = slide.createAutoShape()
autoShape.setShapeType(ShapeType.CLOUD)
autoShape.setAnchor(new Rectangle(300, 40, 200, 100))
autoShape.setLineColor(Color.BLACK)
autoShape.setFillColor(Color.lightGray)
autoShape.setLineWidth(1)
autoShape = slide.createAutoShape()
autoShape.setShapeType(ShapeType.BEVEL)
autoShape.setAnchor(new Rectangle(10, 200, 400, 200))
autoShape.setLineColor(Color.BLACK)
autoShape.setLineWidth(1)
autoShape.verticalAlignment = VerticalAlignment.MIDDLE
def paragraph = autoShape.addNewTextParagraph()
paragraph.textAlign = TextParagraph.TextAlign.CENTER
def run = paragraph.addNewTextRun()
run.text = "Hello"
run.bold = true
run.fontColor = Color.RED
run.fontSize = 20
def os = new FileOutputStream(new File('test.pptx'))
slideShow.write(os)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment