文档库 最新最全的文档下载
当前位置:文档库 › 用poi读取word文档

用poi读取word文档

用poi读取word文档吧:

package org.poi.hwsf.test;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.List;

import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.hwpf.extractor.WordExtractor;

/**
* @author
*
*/
public class PoiTest {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String filename = "test2.doc ";
try {
FileInputStream in = new FileInputStream (filename);
HWPFDocument doc = new HWPFDocument(new FileInputStream(filename));
WordExtractor extractor = new WordExtractor(in);
String[] str = extractor.getParagraphText();
List name = doc.getTextTable().getTextPieces();
// System.out.println( "the result length is : "+str.length());
System.out.println( "the result is : "+str);
for (int i = 0; i < str.length; i++ ) {
System.out.print(str[i]);
}

// HWPFDocument doc = new HWPFDocument(new FileInputStream(filename));
// System.out.println(doc);
// String str = doc.getDataStream().toString();
// System.out.println(str);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
};


}

}

相关文档
相关文档 最新文档