日期:2014-05-17  浏览次数:20700 次

关于Apache poi word
出现了一个很奇怪的现象


//获得文件输入流   
FileInputStream input = new FileInputStream(file);
//创建Document对象
HWPFDocument hDocument = new HWPFDocument(input);
 
问题在创建Document对象时会出异常:
 
java.lang.ClassCastExceptionjava.lang.NoSuchMethodError cannot be cast to java.lang.Exception
java Apache?poi word

------解决方案--------------------
是可以的,估计你文档问题或者jar 的问题。
public static void main(String[] args) throws Exception {
StringBuffer stringBuffer=new StringBuffer(); 
File  file= new File("D:\\121.doc");
//获得文件输入流   
FileInputStream input = new FileInputStream(file);
//创建Document对象
HWPFDocument doc = new HWPFDocument(input);

 //用来获得word文档内容 
        Range range=doc.getRange(); 
        //文档段落数目 
        int paragraphCount=range.numParagraphs(); 
        //遍历段落读取数据 
        for(int i=0;i<paragraphCount;i++) 
        { 
            Paragraph pph=range.getParagraph(i); 
            stringBuffer.append(pph.text()); 
            System.out.println(stringBuffer.toString()); 
        } 
}

------解决方案--------------------
操作word最好用openoffice吧

------解决方案--------------------
你百度下openoffice将word转为html 一大堆