如何从XWPFDocument转换为HWPFDocument

时间:2016-03-12 10:28:46

标签: java apache-poi

如何从XWPFDocument转换为HWPFDocument:

我正在尝试将XWPFDocument转换为HWPFDocument,但我收到了Exception,如下所述。

例外: - java.lang.ClassCastException: org.apache.poi.xwpf.usermodel.XWPFDocument cannot be cast to org.apache.poi.hwpf.HWPFDocument

public class test{
    File docFile=new File(fileName) 
    FileInputStream finStream = new FileInputStream(docFile.getAbsolutePath());
        String myDocFileName = String.valueOf(docFile);
        HWPFDocument doc = null;
        XWPFDocument docx = null;
        if (String.valueOf(myDocFileName.contains(".docx")) == "true") {
            docx = new XWPFDocument(finStream);
            Object o = docx;
           doc = (HWPFDocument) o;///Getting Exception here.......

        } 
        else {
            doc = new HWPFDocument(finStream);
            WordExtractor wordExtract = new WordExtractor(doc);
            myHTML = wordExtract.getText();
         }
 }

0 个答案:

没有答案