Example usage for org.apache.poi.xslf.usermodel XSLFTextShape setText

List of usage examples for org.apache.poi.xslf.usermodel XSLFTextShape setText

Introduction

In this page you can find the example usage for org.apache.poi.xslf.usermodel XSLFTextShape setText.

Prototype

@Override
    public XSLFTextRun setText(String text) 

Source Link

Usage

From source file:Tutorial1.java

License:Apache License

public static void main(String[] args) throws IOException {
    XMLSlideShow ppt = new XMLSlideShow();

    // XSLFSlide#createSlide() with no arguments creates a blank slide
    XSLFSlide blankSlide = ppt.createSlide();

    XSLFSlideMaster master = ppt.getSlideMasters()[0];

    XSLFSlideLayout layout1 = master.getLayout(SlideLayout.TITLE);
    XSLFSlide slide1 = ppt.createSlide(layout1);
    XSLFTextShape[] ph1 = slide1.getPlaceholders();
    XSLFTextShape titlePlaceholder1 = ph1[0];
    titlePlaceholder1.setText("This is a title");
    XSLFTextShape subtitlePlaceholder1 = ph1[1];
    subtitlePlaceholder1.setText("this is a subtitle");

    XSLFSlideLayout layout2 = master.getLayout(SlideLayout.TITLE_AND_CONTENT);
    XSLFSlide slide2 = ppt.createSlide(layout2);
    XSLFTextShape[] ph2 = slide2.getPlaceholders();
    XSLFTextShape titlePlaceholder2 = ph2[0];
    titlePlaceholder2.setText("This is a title");
    XSLFTextShape bodyPlaceholder = ph2[1];
    // we are going to add text by paragraphs. Clear the default placehoder text before that
    bodyPlaceholder.clearText();//w  w  w.  j a  va 2s.  c o m
    XSLFTextParagraph p1 = bodyPlaceholder.addNewTextParagraph();
    p1.setLevel(0);
    p1.addNewTextRun().setText("Level1 text");
    XSLFTextParagraph p2 = bodyPlaceholder.addNewTextParagraph();
    p2.setLevel(1);
    p2.addNewTextRun().setText("Level2 text");
    XSLFTextParagraph p3 = bodyPlaceholder.addNewTextParagraph();
    p3.setLevel(3);
    p3.addNewTextRun().setText("Level3 text");

    FileOutputStream out = new FileOutputStream("slides.pptx");
    ppt.write(out);
    out.close();
}

From source file:easyoffice.powerpoint.PPTMaker.java

private static void replaceContent(XSLFTextShape shape, SlideText data) {
    /*/*  w w w .j  a  v a2  s . c o  m*/
    Given a slide shape, replace it content with SlideText data
     */
    String textInShape = shape.getText();
    String newText = textInShape.replace(String.format(STRING_FORMAT, data.key), data.value);

    XSLFTextRun addedText = shape.setText(newText.replace("\r", "")); // not include break line
    addedText.setFontFamily(HSSFFont.FONT_ARIAL);
    addedText.setFontColor(Color.BLACK);
}

From source file:org.joeffice.presentation.actions.NewSlideAction.java

License:Apache License

private void fillWithText(XSLFSheet slide) {
    String message = NbBundle.getMessage(getClass(), "MSG_EnterTextHere");
    XSLFTextShape[] textShapes = slide.getPlaceholders();
    for (XSLFTextShape textShape : textShapes) {
        textShape.setText(message);
    }/*  ww  w.  j  av  a2  s. com*/
}

From source file:poi.xslf.usermodel.tutorial.Step2.java

License:Apache License

public static void main(String[] args) throws Exception {
    XMLSlideShow ppt = new XMLSlideShow();

    // first see what slide layouts are available by default
    System.out.println("Available slide layouts:");
    for (XSLFSlideMaster master : ppt.getSlideMasters()) {
        for (XSLFSlideLayout layout : master.getSlideLayouts()) {
            System.out.println(layout.getType());
        }/*from  w ww. jav a 2 s  .  c om*/
    }

    // blank slide
    XSLFSlide blankSlide = ppt.createSlide();

    XSLFSlideMaster defaultMaster = ppt.getSlideMasters()[0];

    // title slide
    XSLFSlideLayout titleLayout = defaultMaster.getLayout(SlideLayout.TITLE);
    XSLFSlide slide1 = ppt.createSlide(titleLayout);
    XSLFTextShape title1 = slide1.getPlaceholder(0);
    title1.setText("First Title");

    // title and content
    XSLFSlideLayout titleBodyLayout = defaultMaster.getLayout(SlideLayout.TITLE_AND_CONTENT);
    XSLFSlide slide2 = ppt.createSlide(titleBodyLayout);

    XSLFTextShape title2 = slide2.getPlaceholder(0);
    title2.setText("Second Title");

    XSLFTextShape body2 = slide2.getPlaceholder(1);
    body2.clearText(); // unset any existing text
    body2.addNewTextParagraph().addNewTextRun().setText("First paragraph");
    body2.addNewTextParagraph().addNewTextRun().setText("Second paragraph");
    body2.addNewTextParagraph().addNewTextRun().setText("Third paragraph");

    FileOutputStream out = new FileOutputStream("step2.pptx");
    ppt.write(out);
    out.close();

}

From source file:poi.xslf.usermodel.Tutorial3.java

License:Apache License

public static void main(String[] args) throws IOException {
    XMLSlideShow ppt = new XMLSlideShow();

    XSLFSlide slide = ppt.createSlide();

    XSLFTextShape titleShape = slide.createTextBox();
    titleShape.setPlaceholder(Placeholder.TITLE);
    titleShape.setText("This is a slide title");
    titleShape.setAnchor(new Rectangle(50, 50, 400, 100));

    FileOutputStream out = new FileOutputStream("title.pptx");
    ppt.write(out);//from   w  ww . ja  v a  2 s.c o m
    out.close();
}