HSLF table and example fixes

git-svn-id: https://svn.apache.org/repos/asf/poi/branches/common_sl@1677703 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Andreas Beeker 2015-05-04 22:31:45 +00:00
parent 02e70fdbfe
commit 2aea517704
6 changed files with 110 additions and 138 deletions

View File

@ -17,14 +17,15 @@
package org.apache.poi.hslf.examples; package org.apache.poi.hslf.examples;
import org.apache.poi.hslf.usermodel.*; import java.awt.*;
import java.io.FileOutputStream;
import java.io.IOException;
import org.apache.poi.hslf.model.*; import org.apache.poi.hslf.model.*;
import org.apache.poi.hslf.record.TextHeaderAtom; import org.apache.poi.hslf.record.TextHeaderAtom;
import org.apache.poi.hslf.usermodel.*;
import org.apache.poi.sl.usermodel.ShapeType; import org.apache.poi.sl.usermodel.ShapeType;
import org.apache.poi.sl.usermodel.VerticalAlignment;
import java.io.IOException;
import java.io.FileOutputStream;
import java.awt.*;
/** /**
* Presentation for Fast Feather Track on ApacheconEU 2008 * Presentation for Fast Feather Track on ApacheconEU 2008
@ -60,26 +61,23 @@ public final class ApacheconEU08 {
HSLFSlide slide = ppt.createSlide(); HSLFSlide slide = ppt.createSlide();
HSLFTextBox box1 = new HSLFTextBox(); HSLFTextBox box1 = new HSLFTextBox();
HSLFTextParagraph tr1 = box1.getTextParagraphs(); box1.setRunType(TextHeaderAtom.CENTER_TITLE_TYPE);
tr1.setRunType(TextHeaderAtom.CENTER_TITLE_TYPE); box1.setText("POI-HSLF");
tr1.setText("POI-HSLF");
box1.setAnchor(new Rectangle(54, 78, 612, 115)); box1.setAnchor(new Rectangle(54, 78, 612, 115));
slide.addShape(box1); slide.addShape(box1);
HSLFTextBox box2 = new HSLFTextBox(); HSLFTextBox box2 = new HSLFTextBox();
HSLFTextParagraph tr2 = box2.getTextParagraphs(); box2.setRunType(TextHeaderAtom.CENTRE_BODY_TYPE);
tr2.setRunType(TextHeaderAtom.CENTRE_BODY_TYPE); box2.setText("Java API To Access Microsoft PowerPoint Format Files");
tr2.setText("Java API To Access Microsoft PowerPoint Format Files");
box2.setAnchor(new Rectangle(108, 204, 504, 138)); box2.setAnchor(new Rectangle(108, 204, 504, 138));
slide.addShape(box2); slide.addShape(box2);
HSLFTextBox box3 = new HSLFTextBox(); HSLFTextBox box3 = new HSLFTextBox();
HSLFTextParagraph tr3 = box3.getTextParagraphs(); box3.getTextParagraphs().get(0).getTextRuns().get(0).setFontSize(32);
tr3.getTextRuns()[0].setFontSize(32); box3.setText(
box3.setHorizontalAlignment(HSLFTextBox.AlignCenter);
tr3.setText(
"Yegor Kozlov\r" + "Yegor Kozlov\r" +
"yegor - apache - org"); "yegor - apache - org");
box3.setHorizontalCentered(true);
box3.setAnchor(new Rectangle(206, 348, 310, 84)); box3.setAnchor(new Rectangle(206, 348, 310, 84));
slide.addShape(box3); slide.addShape(box3);
} }
@ -88,16 +86,14 @@ public final class ApacheconEU08 {
HSLFSlide slide = ppt.createSlide(); HSLFSlide slide = ppt.createSlide();
HSLFTextBox box1 = new HSLFTextBox(); HSLFTextBox box1 = new HSLFTextBox();
HSLFTextParagraph tr1 = box1.getTextParagraphs(); box1.setRunType(TextHeaderAtom.TITLE_TYPE);
tr1.setRunType(TextHeaderAtom.TITLE_TYPE); box1.setText("What is HSLF?");
tr1.setText("What is HSLF?");
box1.setAnchor(new Rectangle(36, 21, 648, 90)); box1.setAnchor(new Rectangle(36, 21, 648, 90));
slide.addShape(box1); slide.addShape(box1);
HSLFTextBox box2 = new HSLFTextBox(); HSLFTextBox box2 = new HSLFTextBox();
HSLFTextParagraph tr2 = box2.getTextParagraphs(); box2.setRunType(TextHeaderAtom.BODY_TYPE);
tr2.setRunType(TextHeaderAtom.BODY_TYPE); box2.setText("HorribleSLideshowFormat is the POI Project's pure Java implementation " +
tr2.setText("HorribleSLideshowFormat is the POI Project's pure Java implementation " +
"of the Powerpoint binary file format. \r" + "of the Powerpoint binary file format. \r" +
"POI sub-project since 2005\r" + "POI sub-project since 2005\r" +
"Started by Nick Birch, Yegor Kozlov joined soon after"); "Started by Nick Birch, Yegor Kozlov joined soon after");
@ -111,41 +107,37 @@ public final class ApacheconEU08 {
HSLFSlide slide = ppt.createSlide(); HSLFSlide slide = ppt.createSlide();
HSLFTextBox box1 = new HSLFTextBox(); HSLFTextBox box1 = new HSLFTextBox();
HSLFTextParagraph tr1 = box1.getTextParagraphs(); box1.setRunType(TextHeaderAtom.TITLE_TYPE);
tr1.setRunType(TextHeaderAtom.TITLE_TYPE); box1.setText("HSLF in a Nutshell");
tr1.setText("HSLF in a Nutshell");
box1.setAnchor(new Rectangle(36, 15, 648, 65)); box1.setAnchor(new Rectangle(36, 15, 648, 65));
slide.addShape(box1); slide.addShape(box1);
HSLFTextBox box2 = new HSLFTextBox(); HSLFTextBox box2 = new HSLFTextBox();
HSLFTextParagraph tr2 = box2.getTextParagraphs(); box2.getTextParagraphs().get(0).getTextRuns().get(0).setFontSize(28);
tr2.setRunType(TextHeaderAtom.BODY_TYPE); box2.setRunType(TextHeaderAtom.BODY_TYPE);
tr2.setText( box2.setText(
"HSLF provides a way to read, create and modify MS PowerPoint presentations\r" + "HSLF provides a way to read, create and modify MS PowerPoint presentations\r" +
"Pure Java API - you don't need PowerPoint to read and write *.ppt files\r" + "Pure Java API - you don't need PowerPoint to read and write *.ppt files\r" +
"Comprehensive support of PowerPoint objects"); "Comprehensive support of PowerPoint objects");
tr2.getTextRuns()[0].setFontSize(28);
box2.setAnchor(new Rectangle(36, 80, 648, 200)); box2.setAnchor(new Rectangle(36, 80, 648, 200));
slide.addShape(box2); slide.addShape(box2);
HSLFTextBox box3 = new HSLFTextBox(); HSLFTextBox box3 = new HSLFTextBox();
HSLFTextParagraph tr3 = box3.getTextParagraphs(); box2.getTextParagraphs().get(0).setIndentLevel(1);
tr3.setRunType(TextHeaderAtom.BODY_TYPE); box2.getTextParagraphs().get(0).getTextRuns().get(0).setFontSize(24);
tr3.setText( box3.setRunType(TextHeaderAtom.BODY_TYPE);
box3.setText(
"Rich text\r" + "Rich text\r" +
"Tables\r" + "Tables\r" +
"Shapes\r" + "Shapes\r" +
"Pictures\r" + "Pictures\r" +
"Master slides"); "Master slides");
tr3.getTextRuns()[0].setFontSize(24);
tr3.getTextRuns()[0].setIndentLevel(1);
box3.setAnchor(new Rectangle(36, 265, 648, 150)); box3.setAnchor(new Rectangle(36, 265, 648, 150));
slide.addShape(box3); slide.addShape(box3);
HSLFTextBox box4 = new HSLFTextBox(); HSLFTextBox box4 = new HSLFTextBox();
HSLFTextParagraph tr4 = box4.getTextParagraphs(); box4.setRunType(TextHeaderAtom.BODY_TYPE);
tr4.setRunType(TextHeaderAtom.BODY_TYPE); box4.setText("Access to low level data structures");
tr4.setText("Access to low level data structures");
box4.setAnchor(new Rectangle(36, 430, 648, 50)); box4.setAnchor(new Rectangle(36, 430, 648, 50));
slide.addShape(box4); slide.addShape(box4);
} }
@ -162,8 +154,8 @@ public final class ApacheconEU08 {
for (int j = 0; j < txt1[i].length; j++) { for (int j = 0; j < txt1[i].length; j++) {
TableCell cell = table1.getCell(i, j); TableCell cell = table1.getCell(i, j);
cell.setText(txt1[i][j]); cell.setText(txt1[i][j]);
cell.getTextParagraphs().getTextRuns()[0].setFontSize(10); HSLFTextRun rt = cell.getTextParagraphs().get(0).getTextRuns().get(0);
HSLFTextRun rt = cell.getTextParagraphs().getTextRuns()[0]; rt.setFontSize(10);
rt.setFontName("Arial"); rt.setFontName("Arial");
rt.setBold(true); rt.setBold(true);
if(i == 0){ if(i == 0){
@ -174,7 +166,7 @@ public final class ApacheconEU08 {
rt.setFontSize(28); rt.setFontSize(28);
cell.getFill().setForegroundColor(new Color(235, 239, 241)); cell.getFill().setForegroundColor(new Color(235, 239, 241));
} }
cell.setVerticalAlignment(HSLFTextBox.AnchorMiddle); cell.setVerticalAlignment(VerticalAlignment.MIDDLE);
} }
} }
@ -196,12 +188,10 @@ public final class ApacheconEU08 {
table1.moveTo(100, 100); table1.moveTo(100, 100);
HSLFTextBox box1 = new HSLFTextBox(); HSLFTextBox box1 = new HSLFTextBox();
box1.setHorizontalAlignment(HSLFTextBox.AlignCenter); box1.setHorizontalCentered(true);
HSLFTextParagraph tr1 = box1.getTextParagraphs(); box1.getTextParagraphs().get(0).getTextRuns().get(0).setFontSize(24);
tr1.setText("The source code is available at\r" + box1.setText("The source code is available at\r" +
"http://people.apache.org/~yegor/apachecon_eu08/"); "http://people.apache.org/~yegor/apachecon_eu08/");
HSLFTextRun rt = tr1.getTextRuns()[0];
rt.setFontSize(24);
box1.setAnchor(new Rectangle(80, 356, 553, 65)); box1.setAnchor(new Rectangle(80, 356, 553, 65));
slide.addShape(box1); slide.addShape(box1);
@ -211,16 +201,14 @@ public final class ApacheconEU08 {
HSLFSlide slide = ppt.createSlide(); HSLFSlide slide = ppt.createSlide();
HSLFTextBox box1 = new HSLFTextBox(); HSLFTextBox box1 = new HSLFTextBox();
HSLFTextParagraph tr1 = box1.getTextParagraphs(); box1.setRunType(TextHeaderAtom.TITLE_TYPE);
tr1.setRunType(TextHeaderAtom.TITLE_TYPE); box1.setText("HSLF in Action - 1\rData Extraction");
tr1.setText("HSLF in Action - 1\rData Extraction");
box1.setAnchor(new Rectangle(36, 21, 648, 100)); box1.setAnchor(new Rectangle(36, 21, 648, 100));
slide.addShape(box1); slide.addShape(box1);
HSLFTextBox box2 = new HSLFTextBox(); HSLFTextBox box2 = new HSLFTextBox();
HSLFTextParagraph tr2 = box2.getTextParagraphs(); box2.setRunType(TextHeaderAtom.BODY_TYPE);
tr2.setRunType(TextHeaderAtom.BODY_TYPE); box2.setText(
tr2.setText(
"Text from slides and notes\r" + "Text from slides and notes\r" +
"Images\r" + "Images\r" +
"Shapes and their properties (type, position in the slide, color, font, etc.)"); "Shapes and their properties (type, position in the slide, color, font, etc.)");
@ -234,25 +222,22 @@ public final class ApacheconEU08 {
HSLFSlide slide = ppt.createSlide(); HSLFSlide slide = ppt.createSlide();
HSLFTextBox box1 = new HSLFTextBox(); HSLFTextBox box1 = new HSLFTextBox();
HSLFTextParagraph tr1 = box1.getTextParagraphs(); box1.setRunType(TextHeaderAtom.TITLE_TYPE);
tr1.setRunType(TextHeaderAtom.TITLE_TYPE); box1.setText("HSLF in Action - 2");
tr1.setText("HSLF in Action - 2");
box1.setAnchor(new Rectangle(36, 20, 648, 90)); box1.setAnchor(new Rectangle(36, 20, 648, 90));
slide.addShape(box1); slide.addShape(box1);
HSLFTextBox box2 = new HSLFTextBox(); HSLFTextBox box2 = new HSLFTextBox();
HSLFTextParagraph tr2 = box2.getTextParagraphs(); box2.getTextParagraphs().get(0).getTextRuns().get(0).setFontSize(18);
tr2.getTextRuns()[0].setFontSize(18); box2.setText("Creating a simple presentation from scratch");
tr2.setText("Creating a simple presentation from scratch");
box2.setAnchor(new Rectangle(170, 100, 364, 30)); box2.setAnchor(new Rectangle(170, 100, 364, 30));
slide.addShape(box2); slide.addShape(box2);
HSLFTextBox box3 = new HSLFTextBox(); HSLFTextBox box3 = new HSLFTextBox();
HSLFTextParagraph tr3 = box3.getTextParagraphs(); HSLFTextRun rt3 = box3.getTextParagraphs().get(0).getTextRuns().get(0);
HSLFTextRun rt3 = tr3.getTextRuns()[0];
rt3.setFontName("Courier New"); rt3.setFontName("Courier New");
rt3.setFontSize(8); rt3.setFontSize(8);
tr3.setText( box3.setText(
" SlideShow ppt = new SlideShow();\r" + " SlideShow ppt = new SlideShow();\r" +
" Slide slide = ppt.createSlide();\r" + " Slide slide = ppt.createSlide();\r" +
"\r" + "\r" +
@ -294,9 +279,9 @@ public final class ApacheconEU08 {
HSLFSlide slide = ppt.createSlide(); HSLFSlide slide = ppt.createSlide();
HSLFTextBox box2 = new HSLFTextBox(); HSLFTextBox box2 = new HSLFTextBox();
box2.setHorizontalAlignment(HSLFTextBox.AlignCenter); box2.setHorizontalCentered(true);
box2.setVerticalAlignment(HSLFTextBox.AnchorMiddle); box2.setVerticalAlignment(VerticalAlignment.MIDDLE);
box2.getTextParagraphs().setText("Java Code"); box2.setText("Java Code");
box2.getFill().setForegroundColor(new Color(187, 224, 227)); box2.getFill().setForegroundColor(new Color(187, 224, 227));
box2.setLineColor(Color.black); box2.setLineColor(Color.black);
box2.setLineWidth(0.75); box2.setLineWidth(0.75);
@ -304,9 +289,9 @@ public final class ApacheconEU08 {
slide.addShape(box2); slide.addShape(box2);
HSLFTextBox box3 = new HSLFTextBox(); HSLFTextBox box3 = new HSLFTextBox();
box3.setHorizontalAlignment(HSLFTextBox.AlignCenter); box3.setHorizontalCentered(true);
box3.setVerticalAlignment(HSLFTextBox.AnchorMiddle); box3.setVerticalAlignment(VerticalAlignment.MIDDLE);
box3.getTextParagraphs().setText("*.ppt file"); box3.setText("*.ppt file");
box3.setLineWidth(0.75); box3.setLineWidth(0.75);
box3.setLineColor(Color.black); box3.setLineColor(Color.black);
box3.getFill().setForegroundColor(new Color(187, 224, 227)); box3.getFill().setForegroundColor(new Color(187, 224, 227));
@ -325,16 +310,14 @@ public final class ApacheconEU08 {
HSLFSlide slide = ppt.createSlide(); HSLFSlide slide = ppt.createSlide();
HSLFTextBox box1 = new HSLFTextBox(); HSLFTextBox box1 = new HSLFTextBox();
HSLFTextParagraph tr1 = box1.getTextParagraphs(); box1.setRunType(TextHeaderAtom.TITLE_TYPE);
tr1.setRunType(TextHeaderAtom.TITLE_TYPE); box1.setText("Wait, there is more!");
tr1.setText("Wait, there is more!");
box1.setAnchor(new Rectangle(36, 21, 648, 90)); box1.setAnchor(new Rectangle(36, 21, 648, 90));
slide.addShape(box1); slide.addShape(box1);
HSLFTextBox box2 = new HSLFTextBox(); HSLFTextBox box2 = new HSLFTextBox();
HSLFTextParagraph tr2 = box2.getTextParagraphs(); box2.setRunType(TextHeaderAtom.BODY_TYPE);
tr2.setRunType(TextHeaderAtom.BODY_TYPE); box2.setText(
tr2.setText(
"Rich text\r" + "Rich text\r" +
"Tables\r" + "Tables\r" +
"Pictures (JPEG, PNG, BMP, WMF, PICT)\r" + "Pictures (JPEG, PNG, BMP, WMF, PICT)\r" +
@ -347,25 +330,22 @@ public final class ApacheconEU08 {
HSLFSlide slide = ppt.createSlide(); HSLFSlide slide = ppt.createSlide();
HSLFTextBox box1 = new HSLFTextBox(); HSLFTextBox box1 = new HSLFTextBox();
HSLFTextParagraph tr1 = box1.getTextParagraphs(); box1.setRunType(TextHeaderAtom.TITLE_TYPE);
tr1.setRunType(TextHeaderAtom.TITLE_TYPE); box1.setText("HSLF in Action - 3");
tr1.setText("HSLF in Action - 3");
box1.setAnchor(new Rectangle(36, 20, 648, 50)); box1.setAnchor(new Rectangle(36, 20, 648, 50));
slide.addShape(box1); slide.addShape(box1);
HSLFTextBox box2 = new HSLFTextBox(); HSLFTextBox box2 = new HSLFTextBox();
HSLFTextParagraph tr2 = box2.getTextParagraphs(); box2.getTextParagraphs().get(0).getTextRuns().get(0).setFontSize(18);
tr2.getTextRuns()[0].setFontSize(18); box2.setText("PPGraphics2D: PowerPoint Graphics2D driver");
tr2.setText("PPGraphics2D: PowerPoint Graphics2D driver");
box2.setAnchor(new Rectangle(178, 70, 387, 30)); box2.setAnchor(new Rectangle(178, 70, 387, 30));
slide.addShape(box2); slide.addShape(box2);
HSLFTextBox box3 = new HSLFTextBox(); HSLFTextBox box3 = new HSLFTextBox();
HSLFTextParagraph tr3 = box3.getTextParagraphs(); HSLFTextRun rt3 = box3.getTextParagraphs().get(0).getTextRuns().get(0);
HSLFTextRun rt3 = tr3.getTextRuns()[0];
rt3.setFontName("Courier New"); rt3.setFontName("Courier New");
rt3.setFontSize(8); rt3.setFontSize(8);
tr3.setText( box3.setText(
" //bar chart data. The first value is the bar color, the second is the width\r" + " //bar chart data. The first value is the bar color, the second is the width\r" +
" Object[] def = new Object[]{\r" + " Object[] def = new Object[]{\r" +
" Color.yellow, new Integer(100),\r" + " Color.yellow, new Integer(100),\r" +
@ -449,45 +429,40 @@ public final class ApacheconEU08 {
HSLFSlide slide = ppt.createSlide(); HSLFSlide slide = ppt.createSlide();
HSLFTextBox box1 = new HSLFTextBox(); HSLFTextBox box1 = new HSLFTextBox();
HSLFTextParagraph tr1 = box1.getTextParagraphs(); box1.setRunType(TextHeaderAtom.TITLE_TYPE);
tr1.setRunType(TextHeaderAtom.TITLE_TYPE); box1.setText("HSLF Development Plans");
tr1.setText("HSLF Development Plans");
box1.setAnchor(new Rectangle(36, 21, 648, 90)); box1.setAnchor(new Rectangle(36, 21, 648, 90));
slide.addShape(box1); slide.addShape(box1);
HSLFTextBox box2 = new HSLFTextBox(); HSLFTextBox box2 = new HSLFTextBox();
HSLFTextParagraph tr2 = box2.getTextParagraphs(); box2.getTextParagraphs().get(0).getTextRuns().get(0).setFontSize(32);
tr2.setRunType(TextHeaderAtom.BODY_TYPE); box2.setRunType(TextHeaderAtom.BODY_TYPE);
tr2.getTextRuns()[0].setFontSize(32); box2.setText(
tr2.setText(
"Support for more PowerPoint functionality\r" + "Support for more PowerPoint functionality\r" +
"Rendering slides into java.awt.Graphics2D"); "Rendering slides into java.awt.Graphics2D");
box2.setAnchor(new Rectangle(36, 126, 648, 100)); box2.setAnchor(new Rectangle(36, 126, 648, 100));
slide.addShape(box2); slide.addShape(box2);
HSLFTextBox box3 = new HSLFTextBox(); HSLFTextBox box3 = new HSLFTextBox();
HSLFTextParagraph tr3 = box3.getTextParagraphs(); box3.getTextParagraphs().get(0).setIndentLevel(1);
tr3.setRunType(TextHeaderAtom.BODY_TYPE); box3.setRunType(TextHeaderAtom.BODY_TYPE);
tr3.getTextRuns()[0].setIndentLevel(1); box3.setText(
tr3.setText(
"A way to export slides into images or other formats"); "A way to export slides into images or other formats");
box3.setAnchor(new Rectangle(36, 220, 648, 70)); box3.setAnchor(new Rectangle(36, 220, 648, 70));
slide.addShape(box3); slide.addShape(box3);
HSLFTextBox box4 = new HSLFTextBox(); HSLFTextBox box4 = new HSLFTextBox();
HSLFTextParagraph tr4 = box4.getTextParagraphs(); box4.getTextParagraphs().get(0).getTextRuns().get(0).setFontSize(32);
tr4.setRunType(TextHeaderAtom.BODY_TYPE); box4.setRunType(TextHeaderAtom.BODY_TYPE);
tr4.getTextRuns()[0].setFontSize(32); box4.setText(
tr4.setText(
"Integration with Apache FOP - Formatting Objects Processor"); "Integration with Apache FOP - Formatting Objects Processor");
box4.setAnchor(new Rectangle(36, 290, 648, 90)); box4.setAnchor(new Rectangle(36, 290, 648, 90));
slide.addShape(box4); slide.addShape(box4);
HSLFTextBox box5 = new HSLFTextBox(); HSLFTextBox box5 = new HSLFTextBox();
HSLFTextParagraph tr5 = box5.getTextParagraphs(); box5.getTextParagraphs().get(0).setIndentLevel(1);
tr5.setRunType(TextHeaderAtom.BODY_TYPE); box5.setRunType(TextHeaderAtom.BODY_TYPE);
tr5.getTextRuns()[0].setIndentLevel(1); box5.setText(
tr5.setText(
"Transformation of XSL-FO into PPT\r" + "Transformation of XSL-FO into PPT\r" +
"PPT2PDF transcoder"); "PPT2PDF transcoder");
box5.setAnchor(new Rectangle(36, 380, 648, 100)); box5.setAnchor(new Rectangle(36, 380, 648, 100));
@ -498,16 +473,14 @@ public final class ApacheconEU08 {
HSLFSlide slide = ppt.createSlide(); HSLFSlide slide = ppt.createSlide();
HSLFTextBox box1 = new HSLFTextBox(); HSLFTextBox box1 = new HSLFTextBox();
HSLFTextParagraph tr1 = box1.getTextParagraphs(); box1.setRunType(TextHeaderAtom.CENTER_TITLE_TYPE);
tr1.setRunType(TextHeaderAtom.CENTER_TITLE_TYPE); box1.setText("Questions?");
tr1.setText("Questions?");
box1.setAnchor(new Rectangle(54, 167, 612, 115)); box1.setAnchor(new Rectangle(54, 167, 612, 115));
slide.addShape(box1); slide.addShape(box1);
HSLFTextBox box2 = new HSLFTextBox(); HSLFTextBox box2 = new HSLFTextBox();
HSLFTextParagraph tr2 = box2.getTextParagraphs(); box2.setRunType(TextHeaderAtom.CENTRE_BODY_TYPE);
tr2.setRunType(TextHeaderAtom.CENTRE_BODY_TYPE); box2.setText(
tr2.setText(
"http://poi.apache.org/hslf/\r" + "http://poi.apache.org/hslf/\r" +
"http://people.apache.org/~yegor"); "http://people.apache.org/~yegor");
box2.setAnchor(new Rectangle(108, 306, 504, 138)); box2.setAnchor(new Rectangle(108, 306, 504, 138));

View File

@ -36,17 +36,17 @@ public final class BulletsDemo {
HSLFSlide slide = ppt.createSlide(); HSLFSlide slide = ppt.createSlide();
HSLFTextBox shape = new HSLFTextBox(); HSLFTextBox shape = new HSLFTextBox();
HSLFTextRun rt = shape.getTextParagraphs().getTextRuns()[0]; HSLFTextParagraph rt = shape.getTextParagraphs().get(0);
rt.getTextRuns().get(0).setFontSize(42);
rt.setBullet(true);
rt.setIndent(0); //bullet offset
rt.setLeftMargin(50); //text offset (should be greater than bullet offset)
rt.setBulletChar('\u263A'); //bullet character
shape.setText( shape.setText(
"January\r" + "January\r" +
"February\r" + "February\r" +
"March\r" + "March\r" +
"April"); "April");
rt.setFontSize(42);
rt.setBullet(true);
rt.setBulletOffset(0); //bullet offset
rt.setTextOffset(50); //text offset (should be greater than bullet offset)
rt.setBulletChar('\u263A'); //bullet character
slide.addShape(shape); slide.addShape(shape);
shape.setAnchor(new java.awt.Rectangle(50, 50, 500, 300)); //position of the text box in the slide shape.setAnchor(new java.awt.Rectangle(50, 50, 500, 300)); //position of the text box in the slide

View File

@ -57,13 +57,13 @@ public final class DataExtraction {
out.close(); out.close();
} }
//extract embedded OLE documents int oleIdx=-1, picIdx=-1;
HSLFSlide[] slide = ppt.getSlides(); for (HSLFSlide slide : ppt.getSlides()) {
for (int i = 0; i < slide.length; i++) { //extract embedded OLE documents
HSLFShape[] shape = slide[i].getShapes(); for (HSLFShape shape : slide.getShapes()) {
for (int j = 0; j < shape.length; j++) { if (shape instanceof OLEShape) {
if (shape[j] instanceof OLEShape) { oleIdx++;
OLEShape ole = (OLEShape) shape[j]; OLEShape ole = (OLEShape) shape;
HSLFObjectData data = ole.getObjectData(); HSLFObjectData data = ole.getObjectData();
String name = ole.getInstanceName(); String name = ole.getInstanceName();
if ("Worksheet".equals(name)) { if ("Worksheet".equals(name)) {
@ -81,11 +81,11 @@ public final class DataExtraction {
} }
//save on disk //save on disk
FileOutputStream out = new FileOutputStream(name + "-("+(j)+").doc"); FileOutputStream out = new FileOutputStream(name + "-("+(oleIdx)+").doc");
doc.write(out); doc.write(out);
out.close(); out.close();
} else { } else {
FileOutputStream out = new FileOutputStream(ole.getProgID() + "-"+(j+1)+".dat"); FileOutputStream out = new FileOutputStream(ole.getProgID() + "-"+(oleIdx+1)+".dat");
InputStream dis = data.getData(); InputStream dis = data.getData();
byte[] chunk = new byte[2048]; byte[] chunk = new byte[2048];
int count; int count;
@ -96,16 +96,11 @@ public final class DataExtraction {
out.close(); out.close();
} }
} }
} //Pictures
} else if (shape instanceof HSLFPictureShape) {
picIdx++;
//Pictures HSLFPictureShape p = (HSLFPictureShape) shape;
for (int i = 0; i < slide.length; i++) {
HSLFShape[] shape = slide[i].getShapes();
for (int j = 0; j < shape.length; j++) {
if (shape[j] instanceof HSLFPictureShape) {
HSLFPictureShape p = (HSLFPictureShape) shape[j];
HSLFPictureData data = p.getPictureData(); HSLFPictureData data = p.getPictureData();
String name = p.getPictureName(); String name = p.getPictureName();
int type = data.getType(); int type = data.getType();
@ -132,14 +127,13 @@ public final class DataExtraction {
default: default:
continue; continue;
} }
FileOutputStream out = new FileOutputStream("pict-" + j + ext); FileOutputStream out = new FileOutputStream("pict-" + picIdx + ext);
out.write(data.getData()); out.write(data.getData());
out.close(); out.close();
} }
} }
}
}
} }
private static void usage(){ private static void usage(){

View File

@ -78,7 +78,7 @@ public final class Table extends HSLFGroupShape {
EscherOptRecord opt = new EscherOptRecord(); EscherOptRecord opt = new EscherOptRecord();
opt.setRecordId((short)0xF122); opt.setRecordId((short)0xF122);
opt.addEscherProperty(new EscherSimpleProperty((short)0x39F, 1)); opt.addEscherProperty(new EscherSimpleProperty((short)0x39F, 1));
EscherArrayProperty p = new EscherArrayProperty((short)0x43A0, false, null); EscherArrayProperty p = new EscherArrayProperty((short)(0x4000 | 0x3A0), false, null);
p.setSizeOfElements(0x0004); p.setSizeOfElements(0x0004);
p.setNumberOfElementsInArray(numrows); p.setNumberOfElementsInArray(numrows);
p.setNumberOfElementsInMemory(numrows); p.setNumberOfElementsInMemory(numrows);
@ -122,7 +122,7 @@ public final class Table extends HSLFGroupShape {
EscherContainerRecord spCont = (EscherContainerRecord) getSpContainer().getChild(0); EscherContainerRecord spCont = (EscherContainerRecord) getSpContainer().getChild(0);
List<EscherRecord> lst = spCont.getChildRecords(); List<EscherRecord> lst = spCont.getChildRecords();
EscherOptRecord opt = (EscherOptRecord)lst.get(lst.size()-2); EscherOptRecord opt = (EscherOptRecord)lst.get(lst.size()-2);
EscherArrayProperty p = (EscherArrayProperty)opt.getEscherProperty(1); EscherArrayProperty p = opt.lookup(0x3A0);
for (int i = 0; i < cells.length; i++) { for (int i = 0; i < cells.length; i++) {
TableCell cell = cells[i][0]; TableCell cell = cells[i][0];
int rowHeight = cell.getAnchor().height*MASTER_DPI/POINT_DPI; int rowHeight = cell.getAnchor().height*MASTER_DPI/POINT_DPI;

View File

@ -24,6 +24,7 @@ import java.util.Iterator;
import org.apache.poi.ddf.*; import org.apache.poi.ddf.*;
import org.apache.poi.hslf.record.ColorSchemeAtom; import org.apache.poi.hslf.record.ColorSchemeAtom;
import org.apache.poi.hslf.record.RecordTypes;
import org.apache.poi.sl.usermodel.*; import org.apache.poi.sl.usermodel.*;
import org.apache.poi.util.*; import org.apache.poi.util.*;
@ -484,7 +485,11 @@ public abstract class HSLFShape implements Shape {
} }
public EscherOptRecord getEscherOptRecord() { public EscherOptRecord getEscherOptRecord() {
return getEscherChild(EscherOptRecord.RECORD_ID); EscherOptRecord opt = getEscherChild(EscherOptRecord.RECORD_ID);
if (opt == null) {
opt = getEscherChild(RecordTypes.EscherUserDefined);
}
return opt;
} }
public boolean getFlipHorizontal(){ public boolean getFlipHorizontal(){

View File

@ -230,8 +230,8 @@ public abstract class HSLFTextShape extends HSLFSimpleShape implements TextShape
* fetch the master shape and search for the align property there. * fetch the master shape and search for the align property there.
*/ */
int type = getRunType(); int type = getRunType();
HSLFMasterSheet master = getSheet().getMasterSheet(); if(getSheet() != null && getSheet().getMasterSheet() != null){
if(master != null){ HSLFMasterSheet master = getSheet().getMasterSheet();
HSLFTextShape masterShape = master.getPlaceholderByTextType(type); HSLFTextShape masterShape = master.getPlaceholderByTextType(type);
if(masterShape != null) align = masterShape.getAlignment(); if(masterShape != null) align = masterShape.getAlignment();
} else { } else {