您的位置:首页 > 其它

lucent检索技术之创建索引:使用POI读取txt/word/excel/ppt/pdf内容

2014-09-30 17:00 961 查看
在使用lucent检索文档时,必须先为各文档创建索引。索引的创建即读出文档信息(如文档名称、上传时间、文档内容等),然后再经过分词建索引写入到索引文件里。这里主要是总结下读取各类文档内容这一步。

一、之前做过一个小工具也涉及到读取word和excel内容,采用的是com组件的方式来读取。即导入COM库,引入命名空间(using Microsoft.Office.Interop.Word;using Microsoft.Office.Interop.Excel;),然后读代码如下:

读取word

/// <summary>
/// 读取word2007,excel2003/2007,ppt2003/2007
/// </summary>
/// <param name="filepath"></param>
/// <returns></returns>
public  string ReadOfficeText(string filepath)
{
//docx 、pptx 、xlsx、 ppt 、xls
FileInputStream fs = new FileInputStream(filepath);
POITextExtractor extractor = ExtractorFactory.createExtractor(fs);
string text = extractor.getText();
return text;
}


View Code
但是不知什么原因采用这个方法读取word2003会报错,暂时先用着上面第二点中读取word2003的方法吧。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: