Java 如何从XWPFDocument转换为HWPFDocument
如何从XWPFDocument转换为HWPFDocument: 我正在尝试将XWPFDocument转换为HWPFDocument,但我遇到了如下所述的异常 异常:-Java 如何从XWPFDocument转换为HWPFDocument,java,apache-poi,Java,Apache Poi,如何从XWPFDocument转换为HWPFDocument: 我正在尝试将XWPFDocument转换为HWPFDocument,但我遇到了如下所述的异常 异常:-java.lang.ClassCastException:org.apache.poi.xwpf.usermodel.XWPFDocument不能强制转换为org.apache.poi.hwpf.HWPFDocument public class test{ File docFile=new File(fileName)
java.lang.ClassCastException:org.apache.poi.xwpf.usermodel.XWPFDocument不能强制转换为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();
}
}
你想干什么?你为什么要把一个扔给另一个?(正如您所发现的,这永远不会起作用)我只需要HWPFDocument对象。因此我将Xwpffdocument转换为HWPFDocument“我有一个苹果,我想要一个桔子。我如何使我的苹果变成桔子?”-这基本上就是您要问的问题。仅仅因为两者都是“水果”(使用word文档),并不意味着其中一个与另一个相同