Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何从XWPFDocument转换为HWPFDocument_Java_Apache Poi - Fatal编程技术网

Java 如何从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)

如何从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) 
    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文档),并不意味着其中一个与另一个相同