社区
Eclipse
帖子详情
poi读取word文档(包括图片),如何获取图片的位置
xtt_fion
2013-11-11 08:33:58
用poi读取word文档(包括图片),然后在jsp页面显示,如何确定图片的位置
...全文
1972
5
打赏
收藏
poi读取word文档(包括图片),如何获取图片的位置
用poi读取word文档(包括图片),然后在jsp页面显示,如何确定图片的位置
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
5 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
小博测试成长之路
2014-04-21
打赏
举报
回复
我表示看不懂 可以直接读取有图片的word显示在界面上吗?
zi_wu_xian
2013-11-15
打赏
举报
回复
PageOffice中使用书签来定位和提取图片的方法: WordDocument doc = new WordDocument(); DataRegion dataReg = doc.OpenDataRegion("PO_table"); //保存Word中插入的图片 PageOffice.WordReader.Shape shape = dataReg.OpenShape(1); shape.SaveAsJPG("服务器磁盘路径"); ……
xtt_fion
2013-11-12
打赏
举报
回复
程序中打印出的i就是图片的索引位置 if(pTable.hasPicture(cr)){ //获取图片路径 picpath=this.readPicture(pTable, cr); System.out.println("索引"+i); currentChar=cr.text().charAt(0); tempString+=picpath+"<br/>"; }else {
xtt_fion
2013-11-12
打赏
举报
回复
我这有一个就是用poi读取word文档,可以在jsp页面显示,就还有一个问题是格式不对,你可以参考下。 我下的是poi3.7 package com.sp.model; import java.io.*; import java.util.*; import org.apache.poi.hwpf.HWPFDocument; import org.apache.poi.hwpf.model.PicturesTable; import org.apache.poi.hwpf.usermodel.CharacterRun; import org.apache.poi.hwpf.usermodel.Picture; import org.apache.poi.hwpf.usermodel.Range; public class read { //回车符ASCII private static final short ENTER_ASCII=13; //空格符ASCII private static final short SPACE_ASCII=32; //水平制表符 private static final short TABULATION_ASCII=9; private String htmlText=""; //读取每个字符样式 public String getWordAndStyle(String path) throws Exception{ File file = new File(path); FileInputStream in=new FileInputStream(file.getAbsolutePath()); HWPFDocument doc=new HWPFDocument(in); int length=doc.characterLength(); PicturesTable pTable=doc.getPicturesTable(); htmlText="<h3 align='center'>"+doc.getSummaryInformation().getTitle()+"</h3>"; int TitleLength=doc.getSummaryInformation().getTitle().length(); int imgBegin=0; int imgEnd=0; String tempString=""; String picpath=""; char currentChar=' '; int rowCount=0; for (int i=TitleLength;i<length-1;i++){ Range range=new Range(i, i+1,doc); CharacterRun cr=range.getCharacterRun(0); System.out.print(currentChar); // System.out.print(pTable.hasPicture(cr)); if(pTable.hasPicture(cr)){ //获取图片路径 picpath=this.readPicture(pTable, cr); currentChar=cr.text().charAt(0); tempString+=picpath+"<br/>"; }else { Range range2=new Range(i+1, i+2,doc); CharacterRun cr2=range.getCharacterRun(0); currentChar=cr.text().charAt(0); System.out.print(currentChar+"字符"); if(currentChar==ENTER_ASCII){ tempString+="<br/>"; } else if(currentChar==SPACE_ASCII) tempString+=" "; else if (currentChar==TABULATION_ASCII) tempString+=" "; boolean flag=compareCharStyle(cr,cr2); String fontStyle="<span style='font-family:"+cr.getFontName()+";font-size:"+cr.getFontSize()/2+"pt"; if(cr.isBold()) fontStyle+="font-weight:bold"; if(cr.isItalic()) fontStyle+="font-style:italic"; if(flag&&i!=length-2) tempString+=currentChar; else if(!flag){ htmlText+=fontStyle+"'>"+tempString+currentChar+"</span>"; tempString=""; }else htmlText+=fontStyle+"'>"+tempString+currentChar+"</span>"; } } imgBegin=htmlText.indexOf("INCLUDEPICTURE"); imgEnd=htmlText.indexOf("<img src="); // String str=htmlText. // cr.text().getChars(srcBegin, srcEnd, dst, dstBegin); // String str=htmlText.substring(imgBegin, imgEnd); // htmlText=htmlText.replaceAll(str," "); // System.out.println("字符"+str+"结束"); // System.out.println("起始"+imgBegin); // System.out.println("结束"+imgEnd); System.out.println("文章"+htmlText); return htmlText; } //返回图片的路径 private String readPicture(PicturesTable pTable,CharacterRun cr)throws Exception{ String picpath=""; Picture pic=pTable.extractPicture(cr, false); String afileName=pic.suggestFullFileName(); OutputStream out=new FileOutputStream(new File("d:\\text"+File.separator+afileName)); pic.writeImageContent(out); // htmlText+="<img src='d:\\text\\"+afileName+"'/>"; picpath="<img src='d:\\text\\"+afileName+"'/>"; // System.out.println(picpath); return picpath; } private boolean compareCharStyle(CharacterRun cr1,CharacterRun cr2){ boolean flag=false; if(cr1.isBold()==cr2.isBold()&&cr1.isItalic()==cr2.isItalic()&& cr1.getFontName().equals(cr2.getFontName())&&cr1.getFontSize()==cr2.getFontSize()){ flag=true; } return flag; } // private void writeFile(String s){ // FileOutputStream fos=null; // BufferedWriter bw=null; // try { // File file=new File("e:\\abc.html"); // fos=new FileOutputStream(file); // bw=new BufferedWriter(new OutputStreamWriter(fos)); // bw.write(s); // } catch (Exception e) { // // TODO: handle exception // e.printStackTrace(); // }finally{ // try { // if(bw!=null) // bw.close(); // if(fos!=null) // fos.close(); // } catch (Exception e2) { // // TODO: handle exception // e2.printStackTrace(); // } // } // } // }
叶涛网站推广优化
2013-11-12
打赏
举报
回复
最后有个全包 撸主点击好好看看
POI
读取
word 2003 和 word 2007 的例子
这是一个
POI
读取
word 2003 和 word 2007的例子 是一个Eclipse工程 下载后直接导入工程 运行 src 目录下的 Test java 类即可 这个 rar 包中包含着
POI
读取
word 2003 和 word 2007 所需要的 jar 包 也有需要
读取
的 word 2003 和 word 2007 示例文件 值得注意的是
POI
在
读取
word 文件的时候不会
读取
word 文件中的
图片
信息 还有就是对于 2007 版的 word docx 如果 word 文件中有表格 所有表格中的数据都会在
读取
出来的字符串的最后 ">这是一个
POI
读取
word 2003 和 word 2007的例子 是一个Eclipse工程 下载后直接导入工程 运行 src 目录下的 Test java 类即可 这个 rar 包中包含着
POI
读取
word 2003 和 word 2007 所需要的 jar 包 也有需要
读取
的 word 2003 和 word 2007 示例文件 [更多]
poi
word
图片
文字 目录(源码)
使用
POI
对
图片
插入 目录插入 不用模板文件。 绝对好使的。
POI
操作Excel导入和导出
在企业级应用开发中,Excel报表是一种最常见的报表需求,
POI
是apache的子项目,目标是处理ole2对象。它提供了一组操纵Windows文档的Java API目前比较成熟的是HSSF接口,处理MS Excel(97-2002)对象。它不象我们仅仅是用csv生成的没有格式的可以由Excel转换的东西,而是真正的Excel对象,你可以控制一些属性如sheet,cell等Apache
POI
是Apache软件基金会的开放源码函式库,
POI
提供API给Java程序对Microsoft Office格式档案读和写的功能。结构:HSSF - 提供读写Microsoft Excel格式档案的功能。XSSF - 提供读写Microsoft Excel OOXML格式档案的功能。HWPF - 提供读写Microsoft Word格式档案的功能。HSLF - 提供读写Microsoft Power
Poi
nt格式档案的功能。HDGF - 提供读写Microsoft Visio格式档案的功能。
获取
word文件中的标题、序号、批注等工具类
使用aspose.words,
获取
word文件中的标题,批注,批注所在标题,标题序号,在书签处插入
图片
,在指定文字处插入
图片
等
springboot实现根据指定pdf、word模板文件填充值到文件里面,生成对应的文件
springboot实现根据指定pdf、word模板文件填充值到文件里面,生成对应的文件
Eclipse
58,454
社区成员
49,450
社区内容
发帖
与我相关
我的任务
Eclipse
Java Eclipse
复制链接
扫一扫
分享
社区描述
Java Eclipse
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章