- 浏览: 740154 次
- 性别:
- 来自: 杭州
文章分类
最新评论
-
lgh1992314:
a offset: 26b offset: 24c offse ...
java jvm字节占用空间分析 -
ls0609:
语音实现在线听书http://blog.csdn.net/ls ...
Android 语音输入API使用 -
wangli61289:
http://viralpatel-net-tutorials ...
Android 语音输入API使用 -
zxjlwt:
学习了素人派http://surenpi.com
velocity宏加载顺序 -
tt5753:
谢啦........
Lucene的IndexWriter初始化时的LockObtainFailedException的解决方法
poi3.9版本,官网 http://poi.apache.org/slideshow/how-to-shapes.html
import java.awt.Color; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import org.apache.poi.hslf.HSLFSlideShow; import org.apache.poi.hslf.model.AutoShape; import org.apache.poi.hslf.model.Fill; import org.apache.poi.hslf.model.Freeform; import org.apache.poi.hslf.model.HeadersFooters; import org.apache.poi.hslf.model.Hyperlink; import org.apache.poi.hslf.model.Line; import org.apache.poi.hslf.model.Picture; import org.apache.poi.hslf.model.Shape; import org.apache.poi.hslf.model.ShapeTypes; import org.apache.poi.hslf.model.Slide; import org.apache.poi.hslf.model.SlideMaster; import org.apache.poi.hslf.model.Table; import org.apache.poi.hslf.model.TableCell; import org.apache.poi.hslf.model.TextBox; import org.apache.poi.hslf.model.TextRun; import org.apache.poi.hslf.usermodel.PictureData; import org.apache.poi.hslf.usermodel.RichTextRun; import org.apache.poi.hslf.usermodel.SlideShow; import org.apache.poi.hslf.usermodel.SoundData; public class PPTParseUtil { public static void main(String[] args) throws IOException { SlideShow ppt = new SlideShow(); // 设置标题,底部信息 // presentation-scope headers / footers HeadersFooters hdd = ppt.getSlideHeadersFooters(); hdd.setSlideNumberVisible(true); hdd.setFootersText("Created by POI-HSLF"); // add first slide Slide s1 = ppt.createSlide(); // add second slide Slide s2 = ppt.createSlide(); // retrieve page size. Coordinates are expressed in points (72 dpi) java.awt.Dimension pgsize = ppt.getPageSize(); int pgx = pgsize.width; // slide width int pgy = pgsize.height; // slide height // set new page size ppt.setPageSize(new java.awt.Dimension(1024, 768)); // save changes FileOutputStream out = new FileOutputStream("E:\\logs\\slideshow.ppt"); // get slides Slide[] slide = ppt.getSlides(); for (int i = 0; i < slide.length; i++) { Shape[] sh = slide[i].getShapes(); for (int j = 0; j < sh.length; j++) { // name of the shape String name = sh[j].getShapeName(); // shapes's anchor which defines the position of this shape in // the slide java.awt.Rectangle anchor = sh[j].getAnchor(); if (sh[j] instanceof Line) { Line line = (Line) sh[j]; // work with Line } else if (sh[j] instanceof AutoShape) { AutoShape shape = (AutoShape) sh[j]; // work with AutoShape } else if (sh[j] instanceof TextBox) { TextBox shape = (TextBox) sh[j]; // work with TextBox } else if (sh[j] instanceof Picture) { Picture shape = (Picture) sh[j]; // work with Picture } } } // Drawing a shape on a slide Slide slide2 = ppt.createSlide(); // set slide title TextBox title = slide2.addTitle(); title.setText("Hello, World!"); // Line shape Line line = new Line(); line.setAnchor(new java.awt.Rectangle(50, 50, 100, 20)); line.setLineColor(new Color(0, 128, 0)); line.setLineStyle(Line.LINE_DOUBLE); slide2.addShape(line); // TextBox TextBox txt = new TextBox(); txt.setText("Hello, World!"); txt.setAnchor(new java.awt.Rectangle(300, 100, 300, 50)); // 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.red); rt.setAlignment(TextBox.AlignRight); slide2.addShape(txt); // create shapes of arbitrary geometry java.awt.geom.GeneralPath path = new java.awt.geom.GeneralPath(); path.moveTo(100, 100); path.lineTo(200, 100); path.curveTo(50, 45, 134, 22, 78, 133); path.curveTo(10, 45, 134, 56, 78, 100); path.lineTo(100, 200); path.closePath(); Freeform shape = new Freeform(); shape.setPath(path); slide2.addShape(shape); // Autoshape // 32-point star AutoShape sh1 = new AutoShape(ShapeTypes.Star32); sh1.setAnchor(new java.awt.Rectangle(50, 50, 100, 200)); sh1.setFillColor(Color.red); slide2.addShape(sh1); // Trapezoid AutoShape sh2 = new AutoShape(ShapeTypes.Trapezoid); sh2.setAnchor(new java.awt.Rectangle(150, 150, 100, 200)); sh2.setFillColor(Color.blue); slide2.addShape(sh2); // work with pictures // extract all pictures contained in the presentation PictureData[] pdata = ppt.getPictureData(); for (int ii = 0; ii < pdata.length; ii++) { PictureData pict = pdata[ii]; // picture data byte[] data = pict.getData(); int type = pict.getType(); String ext; switch (type) { case Picture.JPEG: ext = ".jpg"; break; case Picture.PNG: ext = ".png"; break; case Picture.WMF: ext = ".wmf"; break; case Picture.EMF: ext = ".emf"; break; case Picture.PICT: ext = ".pict"; break; default: continue; } FileOutputStream out2 = new FileOutputStream("pict_" + ii + ext); out2.write(data); out2.close(); } // add a new picture to this slideshow and insert it in a new slide int idx = ppt.addPicture(new File("E:\\logs\\clock.png"), Picture.PNG); Picture pict = new Picture(idx); // set image position in the slide pict.setAnchor(new java.awt.Rectangle(100, 100, 300, 200)); Slide slide3 = ppt.createSlide(); slide3.addShape(pict); // This slide has its own background. // Without this line it will use master's background. slide3.setFollowMasterBackground(false); Fill fill = slide3.getBackground().getFill(); int idx1 = ppt.addPicture(new File("E:\\logs\\clock.png"), Picture.PNG); fill.setFillType(Fill.FILL_PATTERN); fill.setPictureData(idx1); // create bulleted lists TextBox shape1 = new TextBox(); RichTextRun rt1 = shape1.getTextRun().getRichTextRuns()[0]; shape1.setText("January\r" + "February\r" + "March\r" + "April"); rt1.setFontSize(42); rt1.setBullet(true); rt1.setBulletOffset(0); // bullet offset rt1.setTextOffset(50); // text offset (should be greater than bullet // offset) rt1.setBulletChar('\u263A'); // bullet character slide3.addShape(shape1); shape1.setAnchor(new java.awt.Rectangle(50, 50, 500, 300)); // position // of the // text box // in the // slide slide3.addShape(shape1); // now retrieve pictures containes in the first slide and save them on // disk slide3 = ppt.getSlides()[0]; Shape[] sh3 = slide3.getShapes(); for (int i2 = 0; i2 < sh3.length; i2++) { if (sh3[i2] instanceof Picture) { Picture pict1 = (Picture) sh3[i2]; PictureData pictData = pict1.getPictureData(); byte[] data = pictData.getData(); int type = pictData.getType(); if (type == Picture.JPEG) { FileOutputStream out3 = new FileOutputStream("slide0_" + i2 + ".jpg"); out3.write(data); out3.close(); } else if (type == Picture.PNG) { FileOutputStream out4 = new FileOutputStream("slide0_" + i2 + ".png"); out4.write(data); out4.close(); } } } // modify background of a slide master SlideMaster master = ppt.getSlidesMasters()[0]; Fill fill1 = master.getBackground().getFill(); int idx11 = ppt .addPicture(new File("E:\\logs\\clock.png"), Picture.PNG); fill1.setFillType(Fill.FILL_PICTURE); fill1.setPictureData(idx11); // read hyperlinks from a slide show Slide[] slide1 = ppt.getSlides(); for (int j = 0; j < slide1.length; j++) { // read hyperlinks from the text runs TextRun[] txt1 = slide1[j].getTextRuns(); if (txt1 == null || txt1.length == 0) { continue; } for (int k = 0; k < txt1.length; k++) { String text = txt1[k].getText(); Hyperlink[] links = txt1[k].getHyperlinks(); if (links != null) for (int l = 0; l < links.length; l++) { Hyperlink link = links[l]; String title1 = link.getTitle(); String address = link.getAddress(); String substring = text.substring(link.getStartIndex(), link.getEndIndex() - 1); // in ppt end index is // inclusive System.out.println(title1 + address + 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 = slide1[j].getShapes(); for (int k = 0; k < sh.length; k++) { Hyperlink link = sh[k].getHyperlink(); if (link != null) { String title1 = link.getTitle(); String address = link.getAddress(); System.out.println(title1 + address); } } } // table data String[][] data = { { "INPUT FILE", "NUMBER OF RECORDS" }, { "Item File", "11,559" }, { "Vendor File", "300" }, { "Purchase History File", "10,000" }, { "Total # of requisitions", "10,200,038" } }; // 创建表格 Slide slide11 = ppt.createSlide(); // create a table of 5 rows and 2 columns Table table = new Table(5, 2); for (int i = 0; i < data.length; i++) { for (int j = 0; j < data[i].length; j++) { TableCell cell = table.getCell(i, j); cell.setText(data[i][j]); RichTextRun rt11 = cell.getTextRun().getRichTextRuns()[0]; rt11.setFontName("Arial"); rt11.setFontSize(10); cell.setVerticalAlignment(TextBox.AnchorMiddle); cell.setHorizontalAlignment(TextBox.AlignCenter); } } // set table borders Line border = table.createBorder(); border.setLineColor(Color.black); border.setLineWidth(1.0); table.setAllBorders(border); // set width of the 1st column table.setColumnWidth(0, 300); // set width of the 2nd column table.setColumnWidth(1, 150); slide11.addShape(table); table.moveTo(100, 100); // retrieve embedded sounds 获取语音信息 SoundData[] sound = ppt.getSoundData(); for (int i = 0; i < sound.length; i++) { // save *WAV sounds on disk if (sound[i].getSoundType().equals(".WAV")) { FileOutputStream out1 = new FileOutputStream( sound[i].getSoundName()); out1.write(sound[i].getData()); out1.close(); } } ppt.write(out); out.close(); } }
发表评论
-
对字符串进行验证之前先进行规范化
2013-09-17 23:18 13884对字符串进行验证之前先进行规范化 应用系统中经常对字 ... -
使用telnet连接到基于spring的应用上执行容器中的bean的任意方法
2013-08-08 09:17 1429使用telnet连接到基于spring的应用上执行容器中 ... -
jdk7和8的一些新特性介绍
2013-07-06 16:07 10069更多ppt内容请查看:htt ... -
java对于接口和抽象类的代理实现,不需要有具体实现类
2013-06-12 09:50 2905原文链接:http://www.javaarch.net/j ... -
Excel2007格式分析和XML解析
2013-06-07 09:56 10609在物料清单采购中,用到excel上传文件解析功能,不 ... -
Java EE 7中对WebSocket 1.0的支持
2013-06-05 09:27 3798原文链接:http://www.javaarch.n ... -
java QRCode生成示例
2013-06-05 09:26 1466原文链接:http://www.javaarch.n ... -
Java Web使用swfobject调用flex图表
2013-05-28 19:05 1079Java Web使用swfobject调用 ... -
spring使用PropertyPlaceholderConfigurer扩展来满足不同环境的参数配置
2013-05-21 15:57 3287spring使用PropertyPlaceholderCon ... -
java国际化
2013-05-20 20:57 4437java国际化 本文来自:http://www.j ... -
RSS feeds with Java
2013-05-20 20:52 1183RSS feeds with Java 原文来自:htt ... -
使用ibatis将数据库从oracle迁移到mysql的几个修改点
2013-04-29 10:40 1633我们项目在公司的大战略下需要从oracle ... -
线上机器jvm dump分析脚本
2013-04-19 10:48 2863#!/bin/sh DUMP_PIDS=`p ... -
eclipse远程部署,静态文件实时同步插件
2013-04-06 20:18 5418eclipse 远程文件实时同步,eclipse远程 ... -
java价格处理的一个问题
2013-03-26 21:21 1791我们经常会处理一些价格,比如从运营上传的文件中将某 ... -
java 服务降级开关设计思路
2013-03-23 16:35 3719java 服务屏蔽开关系统,可以手工降级服务,关闭服 ... -
poi解析excel内存溢出
2013-03-20 22:21 6344真是悲剧啊,一个破内部使用系统20多个人使用的后 ... -
简单web安全框架
2013-03-16 11:56 1498web安全框架,主要用servlet filter方 ... -
基于servlet的简单的页面缓存框架
2013-03-11 19:27 1177基于servlet的页面级缓存框架的基本用法: 代码参考: ... -
Eclipse使用过程中出现java.lang.NoClassDefFoundError的解决方案
2013-02-01 17:22 1472如果jdk,classpath设置正确,突然在eclipse ...
相关推荐
poi操作ppt完整示例程序,包括java实现的demo+POI-3.15的所有jar文件。poi操作ppt完整示例程序,包括java实现的demo+POI-3.15的所有jar文件。
poi操作ppt图表史上最完整示例演示.zip 示例包含圆饼图、柱状图、线性图、面积图
主要介绍了java使用poi读取ppt文件和poi读取excel、word示例,需要的朋友可以参考下
这是一个用Java程序读写操作Excel文件的例子。 例子用到了Apache POI项目...Apache POI项目中还提供了Java操作Word、PPT、Visio等类型文件的方法。 这个例子是我的一个叫姚楠学生写的,现在拿出来供大家分享
主要为大家详细介绍了java使用POI实现html和word的相互转换,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
POI是Java编写的免费开源的跨平台的读写Microsoft Office文档的API,可读写的文档包括WORD、EXCEL、PPT等。这里是最新的5.1.0版本jar包和示例程序,参考示例程序可以写成自己读写文档的程序。本人用POI转PPT为可在线...
apache poi jar包,4.1.2 版本,包含示例代码,说明文档,操作ppt,word ,excel
该demo是java读取office文档的示例demo。包含所需要的jar包。可以读取Excel、word、pdf、ppt等
docx4j是Java操作office2007+中的Word、Excel、PPT的开源项目,其主要针对WordXML同时也可以处理Excel和PPT,比POI要强大很多(POI对Word2007支持很弱)。 资源中包含docx4j项目的jar包(及主要依赖Jar)、javadoc...
docx4j是Java操作office2007+中的Word、Excel、PPT的开源项目,其主要针对WordXML同时也可以处理Excel和PPT,比POI要强大很多