还真没这么做过,解析xml和pdf什么的人家有标记啊,考虑了几个思路,你可以试试
1.word转xml呢?然后你去解析xml
2.文件下载完word后,是一个file然后你io流给他读成1个StringBuffer,
然后,比如融资申请人等字段,是固定的,你根据这些字段,解析这个大字符串。
祝你成功
需要借助第三方工具才能读取word的内容。然后在进行整理
package com;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.hwpf.usermodel.Paragraph;
import org.apache.poi.hwpf.usermodel.Range;
import org.apache.poi.hwpf.usermodel.Table;
import org.apache.poi.hwpf.usermodel.TableCell;
import org.apache.poi.hwpf.usermodel.TableIterator;
import org.apache.poi.hwpf.usermodel.TableRow;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
public class Word {
/**
* 读取word文档的表格数据
*
* @param filePath
* @return List
*/
public static List readWordCell(String filePath) {
FileInputStream in = null;
POIFSFileSystem pfs = null;
List list = new ArrayList();
try {
in = new FileInputStream(filePath);// 载入文档
pfs = new POIFSFileSystem(in);
HWPFDocument hwpf = new HWPFDocument(pfs);
Range range = hwpf.getRange();// 得到文档的读取范围
TableIterator it = new TableIterator(range);
// 迭代文档中的表格
if (it.hasNext()) {
TableRow tr = null;
TableCell td = null;
Paragraph para = null;
String lineString;
String cellString;
Table tb = (Table) it.next();
// 迭代行,从第2行开始
for (int i = 2; i < tb.numRows(); i++) {
tr = tb.getRow(i);
lineString = "";
for (int j = 0; j < tr.numCells(); j++) {
td = tr.getCell(j);// 取得单元格
// 取得单元格的内容
for (int k = 0; k < td.numParagraphs(); k++) {
para = td.getParagraph(k);
cellString = para.text();
if (cellString != null
&& cellString.compareTo("") != 0) {
// 如果不trim,取出的内容后会有一个乱码字符
cellString = cellString.trim() + "|";
}
lineString += cellString;
}
}
// 去除字符串末尾的一个管道符
if (lineString != null && lineString.compareTo("") != 0) {
lineString = lineString.substring(0, lineString
.length() - 1);
}
list.add(lineString);
}
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (null != in) {
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return list;
}
public static void main(String[] args) {
List list = Word.readWordCell("D:\20161125.doc");
for (Iterator iter = list.iterator(); iter.hasNext();) {
String str = (String) iter.next();
System.err.println(str);
}
}
}
根据POI进行解析word文档,然后在根据你的word文档的格式进行获取你想要是数据。最后insert into 入库。
所依赖的jar包poi-3.8-beta5-20111217.jar
poi-scratchpad-3.8-beta5-20111217.jar
非常不建议解析word,因为存在格式问题,获取准确数据很难,兼容性也很差。
有插件可以支持,但是具体使用过程中,如果栏目增加空格或者字体改变,翻页都会影响到读取的准确性。
而且word版本支持也有问题,不同版本要用到不同的插件。