ASF Bugzilla – Attachment 23733 Details for
Bug 47291
Cannot open link correctly which insert in ppt
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
export a text box to ppt with POI
ExportToPPT.java (text/plain), 4.31 KB, created by
lisa
on 2009-05-30 21:08:53 UTC
(
hide
)
Description:
export a text box to ppt with POI
Filename:
MIME Type:
Creator:
lisa
Created:
2009-05-30 21:08:53 UTC
Size:
4.31 KB
patch
obsolete
>package testPOI_PPT; > >import java.awt.Color; >import java.awt.Rectangle; >import java.io.FileInputStream; >import java.io.FileNotFoundException; >import java.io.FileOutputStream; >import java.io.IOException; >import java.io.InputStream; > >import org.apache.poi.hslf.HSLFSlideShow; >import org.apache.poi.hslf.model.AutoShape; >import org.apache.poi.hslf.model.Hyperlink; >import org.apache.poi.hslf.model.Line; >import org.apache.poi.hslf.model.OLEShape; >import org.apache.poi.hslf.model.Shape; >import org.apache.poi.hslf.model.ShapeTypes; >import org.apache.poi.hslf.model.Sheet; >import org.apache.poi.hslf.model.Slide; >import org.apache.poi.hslf.model.TextBox; >import org.apache.poi.hslf.model.TextRun; >import org.apache.poi.hslf.model.TextShape; >import org.apache.poi.hslf.usermodel.ObjectData; >import org.apache.poi.hslf.usermodel.RichTextRun; >import org.apache.poi.hslf.usermodel.SlideShow; >import org.apache.poi.hssf.usermodel.HSSFWorkbook; >import org.apache.poi.hwpf.HWPFDocument; > > > > >public class ExportToPPT { > > > > public static void drawingShape() throws IOException{ > SlideShow ppt = new SlideShow(); > > Slide slide = ppt.createSlide(); > ppt.setPageSize(new java.awt.Dimension(768, 1024)); > > TextBox txt = new TextBox(); > txt.setText("Account Manager ID"); > > txt.setFillColor(Color.green); > Hyperlink link = new Hyperlink(); > link.setId(1); > link.setTitle("mailto:lifeng.qian@china.jinfonet.com"); > link.setAddress("lifeng.qian@china.jinfonet.com"); > > > txt.setHyperlink(link); > > txt.setVerticalAlignment(TextShape.AlignCenter); > > txt.setHorizontalAlignment(TextShape.AlignCenter); > txt.setLineColor(Color.black); > txt.setLineDashing(1); > txt.setLineStyle(2); > txt.setLineWidth(0.1); > //wordwrap = true > txt.setWordWrap(TextShape.WrapSquare); > txt.setAnchor(new java.awt.Rectangle(200, 100, 200, 100)); > > //use RichTextRun to work with the text format > RichTextRun rt = txt.getTextRun().getRichTextRuns()[0]; > rt.setFontSize(32); > rt.setFontName("Arial"); > rt.setBold(true); > rt.setItalic(true); > rt.setUnderlined(true); > rt.setFontColor(Color.white); > > rt.setAlignment(TextBox.AlignRight); > rt.setStrikethrough(true); > > > slide.addShape(txt); > > AutoShape sh1 = new AutoShape(ShapeTypes.Star32); > sh1.setAnchor(new java.awt.Rectangle(50, 50, 100, 200)); > sh1.setFillColor(Color.red); > sh1.setHyperlink(link); > slide.addShape(sh1); > > FileOutputStream out = new FileOutputStream("d:\\temp\\slideshow.ppt"); > ppt.write(out); > out.close(); > > } > > > public static void readHyperlinek() throws IOException{ > FileInputStream is = new FileInputStream("D:\\temp\\slideshow.ppt"); > SlideShow ppt = new SlideShow(is); > is.close(); > > Slide[] slide = ppt.getSlides(); > for (int j = 0; j < slide.length; j++) { > > //read hyperlinks from the text runs > TextRun[] txt = slide[j].getTextRuns(); > for (int k = 0; k < txt.length; k++) { > String text = txt[k].getText(); > Hyperlink[] links = txt[k].getHyperlinks(); > if(links != null) for (int l = 0; l < links.length; l++) { > Hyperlink link = links[l]; > String title = link.getTitle(); > String address = link.getAddress(); > String substring = text.substring(link.getStartIndex(), link.getEndIndex()-1); //in ppt end index is inclusive > System.out.println(substring ); > System.out.println(substring ); > } > } > > //in PowerPoint you can assign a hyperlink to a shape without text, > //for example to a Line object. The code below demonstrates how to > //read such hyperlinks > Shape[] sh = slide[j].getShapes(); > for (int k = 0; k < sh.length; k++) { > Hyperlink link = sh[k].getHyperlink(); > if(link != null) { > String title = link.getTitle(); > String address = link.getAddress(); > System.out.print(title + " = "); > System.out.println(address); > } > } > } > > } > > > > > > > public static void main(String[] args) throws IOException { > drawingShape(); > readHyperlinek(); > > } > >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 47291
: 23733