public static void main(String[] args) throws Exception {
SlideShow ppt = new SlideShow();
- Slide slide = ppt.createSlide();
+ Slide slideA = ppt.createSlide();
+ Slide slideB = ppt.createSlide();
+ Slide slideC = ppt.createSlide();
- TextBox shape = new TextBox();
- shape.setText("Apache POI");
- Rectangle anchor = new Rectangle(100, 100, 200, 50);
- shape.setAnchor(anchor);
+ // link to a URL
+ TextBox textBox1 = new TextBox();
+ textBox1.setText("Apache POI");
+ textBox1.setAnchor(new Rectangle(100, 100, 200, 50));
- String text = shape.getText();
+ String text = textBox1.getText();
Hyperlink link = new Hyperlink();
link.setAddress("http://www.apache.org");
- link.setTitle(shape.getText());
+ link.setTitle(textBox1.getText());
int linkId = ppt.addHyperlink(link);
- shape.setHyperlink(linkId, 0, text.length());
+ // apply link to the text
+ textBox1.setHyperlink(linkId, 0, text.length());
- slide.addShape(shape);
+ slideA.addShape(textBox1);
+
+ // link to another slide
+ TextBox textBox2 = new TextBox();
+ textBox2.setText("Go to slide #3");
+ textBox2.setAnchor(new Rectangle(100, 300, 200, 50));
+
+ Hyperlink link2 = new Hyperlink();
+ link2.setAddress(slideC);
+ ppt.addHyperlink(link2);
+
+ // apply link to the whole shape
+ textBox2.setHyperlink(link2);
+
+ slideA.addShape(textBox2);
FileOutputStream out = new FileOutputStream("hyperlink.ppt");
ppt.write(out);
public static final byte LINK_PREVIOUSSLIDE = InteractiveInfoAtom.LINK_PreviousSlide;
public static final byte LINK_FIRSTSLIDE = InteractiveInfoAtom.LINK_FirstSlide;
public static final byte LINK_LASTSLIDE = InteractiveInfoAtom.LINK_LastSlide;
+ public static final byte LINK_SLIDENUMBER = InteractiveInfoAtom.LINK_SlideNumber;
public static final byte LINK_URL = InteractiveInfoAtom.LINK_Url;
public static final byte LINK_NULL = InteractiveInfoAtom.LINK_NULL;
title = "LAST";
address = "1,-1,LAST";
break;
+ case LINK_SLIDENUMBER:
+ break;
default:
title = "";
address = "";
return address;
}
+ public void setAddress(Slide slide) {
+ String href = slide._getSheetNumber() + ","+slide.getSlideNumber()+",Slide " + slide.getSlideNumber();
+ setAddress(href);;
+ setTitle("Slide " + slide.getSlideNumber());
+ setType(Hyperlink.LINK_SLIDENUMBER);
+ }
+
public void setAddress(String str) {
address = str;
}
ExHyperlink ctrl = new ExHyperlink();
ExHyperlinkAtom obj = ctrl.getExHyperlinkAtom();
obj.setNumber(objectId);
- ctrl.setLinkURL(link.getAddress());
+ if(link.getType() == Hyperlink.LINK_SLIDENUMBER) {
+ ctrl.setLinkURL(link.getAddress(), 0x30);
+ } else {
+ ctrl.setLinkURL(link.getAddress());
+ }
ctrl.setLinkTitle(link.getTitle());
lst.addChildAfter(ctrl, objAtom);
link.setId(objectId);