如何从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();
}
}