下载lius
http://sourceforge.net/projects/lius/
1、解析word
package liusextract;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import lius.index.msword.WordIndexer;
public class wordtest {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
WordIndexer wi=new WordIndexer();
File f=new File("./htmls/ddd.doc");
try {
wi.setStreamToIndex(new FileInputStream(f));
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String text=wi.getContent();
System.out.print(text);
}
}
效果

2、excel
package liusextract;
import lius.index.excel.ExcelIndexer;
import java.io.*;
public class exceltest {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
ExcelIndexer ei=new ExcelIndexer();
File f=new File("./htmls/book1.xls");
try {
ei.setStreamToIndex(new FileInputStream(f));
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String text=ei.getContent();
System.out.print(text);
}
}
本文提供了一个使用LIUS库从Microsoft Word和Excel文件中提取文本内容的Java示例代码。该示例展示了如何初始化WordIndexer和ExcelIndexer类,并通过设置文件输入流来获取文档的内容。

被折叠的 条评论
为什么被折叠?



