- 浏览: 1232912 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (461)
- 心得体会 (166)
- Hibernate (9)
- Spring (12)
- Struts1 (3)
- Ajax (4)
- Java (54)
- 其他技术 (21)
- 数据库 (29)
- EXT (0)
- Struts2 (7)
- Xml (3)
- HTML (5)
- JavaScript (12)
- 面试相关 (3)
- BLOG (11)
- 计算机 (11)
- PMP (0)
- OGNL (1)
- LINUX (79)
- AIX (1)
- Ubuntu (14)
- Android (1)
- hadoop (3)
- LINUX debian (3)
- 心得体会 eclipse (2)
- JSTL (1)
- 心得体会 hadoop cdh3u5 (2)
- maven (5)
- Hive (1)
- 心得体会 工具使用 (3)
- spring data jpa Query By Example(QBE) (1)
- nginx (2)
- Apache (1)
- mysql (6)
- LINUX mysql (2)
- freemaker (1)
- 心得体会 FastDFS Nginx 断点续传 (1)
- LINUX FastDFS Nginx 断点续传 (1)
- 心得体会 Mybatis (2)
- 心得体会 mysql (4)
- php (1)
- logback 简介 (5)
- EL (1)
- Tomcat (2)
- win7 (1)
- LINUX maven (1)
- scrumworks (1)
- linux nginx (6)
- svn linux (1)
- mac (3)
- mac git (1)
- git (1)
- nexus (2)
- golang (1)
- LINUX Redis (1)
- mac oracle (1)
最新评论
-
a785975139:
有用
MySQL Error :SHOW PROFILES -
yijiulove:
弄了半天,参照你的方法解决了.特来感谢,知道可能是先加载,但是 ...
Spring和Mybatis整合时无法读取properties的处理方案 -
chenjinqi1987:
Missing com.sun.jdmk:jmxtools:jar:1.2.1 -
leifeng2:
请问怎么使用,运行之后d盘符没有生产音频文件呢?
java录音程序 -
sundful:
chenghong726 写道你好,我也遇到你这样的问题,按照 ...
Spring和Mybatis整合时无法读取properties的处理方案
public class WordExtractor { public WordExtractor() { } public String extractText(InputStream in) throws IOException { ArrayList text = new ArrayList(); POIFSFileSystem fsys = new POIFSFileSystem(in); DocumentEntry headerProps = (DocumentEntry) fsys.getRoot().getEntry("WordDocument"); DocumentInputStream din = fsys.createDocumentInputStream("WordDocument"); byte[] header = new byte[headerProps.getSize()]; din.read(header); din.close(); // Prende le informazioni dall'header del documento int info = LittleEndian.getShort(header, 0xa); boolean useTable1 = (info & 0x200) != 0; //boolean useTable1 = true; // Prende informazioni dalla piece table int complexOffset = LittleEndian.getInt(header, 0x1a2); //int complexOffset = LittleEndian.getInt(header); String tableName = null; if (useTable1) { tableName = "1Table"; } else { tableName = "0Table"; } DocumentEntry table = (DocumentEntry) fsys.getRoot().getEntry(tableName); byte[] tableStream = new byte[table.getSize()]; din = fsys.createDocumentInputStream(tableName); din.read(tableStream); din.close(); din = null; fsys = null; table = null; headerProps = null; int multiple = findText(tableStream, complexOffset, text); StringBuffer sb = new StringBuffer(); int size = text.size(); tableStream = null; for (int x = 0; x < size; x++) { WordTextPiece nextPiece = (WordTextPiece) text.get(x); int start = nextPiece.getStart(); int length = nextPiece.getLength(); boolean unicode = nextPiece.usesUnicode(); String toStr = null; if (unicode) { toStr = new String(header, start, length * multiple, "UTF-16LE"); } else { toStr = new String(header, start, length, "ISO-8859-1"); } sb.append(toStr).append(" "); } return sb.toString(); } private static int findText(byte[] tableStream, int complexOffset, ArrayList text) throws IOException { //actual text int pos = complexOffset; int multiple = 2; //skips through the prms before we reach the piece table. These contain data //for actual fast saved files while (tableStream[pos] == 1) { pos++; int skip = LittleEndian.getShort(tableStream, pos); pos += 2 + skip; } if (tableStream[pos] != 2) { throw new IOException("corrupted Word file"); } else { //parse out the text pieces int pieceTableSize = LittleEndian.getInt(tableStream, ++pos); pos += 4; int pieces = (pieceTableSize - 4) / 12; for (int x = 0; x < pieces; x++) { int filePos = LittleEndian.getInt(tableStream, pos + ((pieces + 1) * 4) + (x *<IMG src="/images/smiles/icon_cool.gif">+ 2); boolean unicode = false; if ((filePos & 0x40000000) == 0) { unicode = true; } else { unicode = false; multiple = 1; filePos &= ~(0x40000000); //gives me FC in doc stream filePos /= 2; } int totLength = LittleEndian.getInt(tableStream, pos + (x + 1) * 4) - LittleEndian.getInt(tableStream, pos + (x * 4)); WordTextPiece piece = new WordTextPiece(filePos, totLength, unicode); text.add(piece); } } return multiple; } public static void main(String[] args){ WordExtractor w = new WordExtractor(); POIFSFileSystem ps = new POIFSFileSystem(); try{ File file = new File("C:\\test.doc"); InputStream in = new FileInputStream(file); String s = w.extractText(in); System.out.println(s); }catch(Exception e){ e.printStackTrace(); } } } class WordTextPiece { private int _fcStart; private boolean _usesUnicode; private int _length; public WordTextPiece(int start, int length, boolean unicode) { _usesUnicode = unicode; _length = length; _fcStart = start; } public boolean usesUnicode() { return _usesUnicode; } public int getStart() { return _fcStart; } public int getLength() { return _length; } }
public boolean writeWordFile(String path, String content) { boolean w = false; try { // byte b[] = content.getBytes("ISO-8859-1"); byte b[] = content.getBytes(); ByteArrayInputStream bais = new ByteArrayInputStream(b); POIFSFileSystem fs = new POIFSFileSystem(); DirectoryEntry directory = fs.getRoot(); DocumentEntry de = directory.createDocument("WordDocument", bais); FileOutputStream ostream = new FileOutputStream(path); fs.writeFilesystem(ostream); bais.close(); ostream.close(); } catch (IOException e) { e.printStackTrace(); } return w; }
当然这几个jar是少不了的
poi-2.5.1-final-20040804.jar
poi-contrib-2.5.1-final-20040804.jar
poi-scratchpad-2.5.1-final-20040804.jar
发表评论
-
Java数字、货币值和百分数等的格式化处理
2016-09-13 18:36 907如果我们用下列语句输出一个数 System.out.pri ... -
jstack(查看线程)、jmap(查看内存)和jstat(性能分析)命令
2016-08-17 09:01 1106公司内部同事分享的一篇文章 周末看到一个用jstack查看死锁 ... -
jstat查看jvm的GC情况[转]
2016-08-17 08:58 757jps(Java Virtual Machine Proce ... -
Java 7, Ubuntu 12.10 64bit issues
2015-04-13 11:57 1340At first Maven failed with the ... -
Map遍历的两种方式
2014-10-20 11:09 880第一种: Map map = new HashMap() ... -
对Map按key和value分别排序
2014-10-20 11:01 923一.理论准备 Map是键值对的集合接口, ... -
【转】程序包com.sun.image.codec.jpeg不存在 问题的完美解决
2014-10-09 13:43 1253maven下面编译失败,失败提示信息为:程序包com.sun ... -
关于系统读取properties配置文件的路径问题,包括打成jar包的运行文件
2014-10-08 18:05 1795在当前的一个项目中, ... -
java中的equals和hashCode(转载)
2014-01-15 14:01 838在某些时候,我们需要判断两个对象是否相等。Java的每个类都继 ... -
关于java中BufferedReader的read()及readLine()方法的使用注意
2013-06-05 16:08 2575以前学习的时候也没有太在意,在项目中使用到了才发现呵呵 1 ... -
java -cp
2013-04-19 12:03 1423java -cp classpath Specify a ... -
maven 打包可执行jar的方法
2013-04-19 12:02 48461.修改pom.xml增加如下内容 [html] ... -
Java 反射测试
2010-08-10 16:54 1276import java.lang.reflect.Invoca ... -
Creating Dynamic Web Project using Maven in Eclipse
2010-08-10 13:10 2823While using Maven as build tool ... -
建立你自己的本地仓库(Maven仓库管理-Nexus)
2010-07-02 13:34 4073这一个章节,我分两部分来介绍,首先介绍一下Maven的仓库,然 ... -
Java枚举类
2010-04-13 11:30 67811.创建一个最简单的枚 ... -
Java堆.栈和常量池 笔记
2010-04-07 09:26 11971.寄存器:最快的存储区, 由编译器根据需求进行分配,我们在程 ... -
探讨代理模式与Java反射机制的应用
2010-04-01 09:53 1057代理模式,相信大多数人都非常熟悉,常见的实现方式是通过公共接 ... -
Java的代理模式(通过公共接口实现)
2010-04-01 09:51 1205代理模式的一种常见的实现方案是,定义一个接口或抽象类,并派生出 ... -
Java多线程编程要点
2010-03-31 09:30 10771、 认识Thread和Runnable Java中实现 ...
相关推荐
使用POI读写Word doc文件 Apache poi的hwpf模块是专门用来对word doc文件进行读写操作的。在hwpf里面我们使用HWPFDocument来表示一个word doc文档
poi实现对word读写操作源码,内包含jar包,还有相关的代码
poi实现对word读写操作实例源码Java源码
java读写Excel,POI.JAR,Word内容读取
poi-tl解析Word文档,包含表格类型的也可以
poi读写word模板/JAVA生成word包
使用poi将多个word合并,本方法经过测试,目前只支持多个doc格式合并成一个doc,如果是docx格式生成后打不开
资源描述了poi对于word的操作,poi合并word文档,poi设置word页码,内含maven依赖文档和完整代码,是一个完整工程,打开即可用
poi读写excel,poi总结; poi读写excel,poi总结 poi读写excel,poi总结
这是一个POI读取word 2003 和 word 2007的例子 是一个Eclipse工程 下载后直接导入工程 运行 src 目录下的 Test java 类即可 这个 rar 包中包含着 POI 读取word 2003 和 word 2007 所需要的 jar 包 也有需要读取的 ...
poi生成wordpoi生成wordpoi生成wordpoi生成wordpoi生成wordpoi生成wordpoi生成wordpoi生成wordpoi生成word
poi读取word代码,可以通过此代码实现对word中的文本、图片、表格的读取。
java 使用POI合并两个word文档.docx
Apache poi 根据word模板生成word报表 替换 循环列表 图片,代码调试过了,修改相应的图片位置,word模板路径即可运行
java使用poi操作.doc word模板替换,循环插入表格
一个使用Apache的poi使用word模板循环输出表格行并导出的例子
通过POI将图片插入word文档中,写文字就简单了自己摸索
android使用POI操作word docx文档,根据 【***】这种标识规则,替换掉docx文档中的内容
java使用poi,根据模板,生成word文档.
poi读写excelpoi读写excelpoi读写excelpoi读写excelpoi读写excelpoi读写excelpoi读写excelpoi读写excelpoi读写excel