导出到EXCEL模板问题

有两种导出模板 XSSFWorkbook wbs = new XSSFWorkbook(is); 

                       和XSSFWorkbook wbs = new XSSFWorkbook(is);

使用不当就会报错:org.apache.poi.poifs.filesystem.OfficeXmlFileException: The supplied data appears to be in the Office 2007+ XML. You are calling the part of POI that deals with OLE2 Office Documents. You need to call a different part of POI to process this data (eg XSSF instead of HSSF)


使用什么方法能够匹配两种模板呢?


    FileInputStream is = new FileInputStream(new File(destFileName));
                    FileInputStream is1 = new FileInputStream(new File(destFileName));
                    Workbook wbs = null;
                    try {
                        wbs = new HSSFWorkbook(is);
                   } catch (Exception ex) {
                       wbs = new XSSFWorkbook(is1);
                    }

这里为什么要获取两次文件流呢,是因为在 wbs = new HSSFWorkbook(is)操作时改变了流,具体源码不得而知。

你可能感兴趣的:(导出到EXCEL模板问题)