簡體   English   中英

apache poi 4.X, 5.X with net.sf.jxls.jxls-core causes java.lang.NoSuch MethodError: org.apache.poi.ss.usermodel.cell.getCellType() error

[英]apache poi 4.X, 5.X with net.sf.jxls.jxls-core causes java.lang.NoSuch MethodError: org.apache.poi.ss.usermodel.cell.getCellType() error

        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi</artifactId>
            <version>4.1.2</version>
        </dependency>
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml</artifactId>
            <version>4.1.2</version>
        </dependency>
        <dependency>
            <groupId>org.jxls</groupId>
            <artifactId>jxls-poi</artifactId>
            <version>2.10.0</version>
        </dependency>
        <dependency>
            <groupId>org.jxls</groupId>
            <artifactId>jxls</artifactId>
            <version>2.10.0</version>
        </dependency>
        <dependency>
            <groupId>net.sf.jxls</groupId>
            <artifactId>jxls-core</artifactId>
            <version>1.0.6</version>
        </dependency>

pom.xml

InputStream is = null;
OutputStream os = null;
Workbook resultWorkbook = null;

try {
            String fileName = map.get("fileName").toString();
            String templateName = map.get("templateName").toString();
            Map<String, Object> data = (Map<String, Object>) map.get("data");

                String tempDirPath = request.getSession().getServletContext().getRealPath("/assets/template");
                File templateFile = new File(tempDirPath + File.separator + templateName);
                is = new BufferedInputStream(new FileInputStream(templateFile));
                XLSTransformer transformer = new XLSTransformer();
                resultWorkbook = transformer.transformXLS(is, data);
                //autoSizeColumns(resultWorkbook);
                response.setHeader("Content-disposition", "attachment;filename=" + 
  this.specialCharacterConversion(request, fileName) + ".xlsx");
                response.setContentType("application/x-msexcel");
                os = response.getOutputStream();
                resultWorkbook.write(os);
                os.flush();
 } catch(IOException | InvalidFormatException e) {
            throw new Exception(e.getMessage());
        } 

resultWorkbook = transformer.transformXLS(is, data); 在這個區域,出現 java.lang.NoSuch MethodError: org.apache.poi.ss.userModel.cell.getCellType() 錯誤。

我想使用 apache poi 至少版本 4.1.2。

項目org.jxlsnet.sf.jxls是不同的項目。 net.sf.jxls自 2014 年以來似乎已經死了。它只適用apache poi 3.9 因此,如果以后要使用apache poi版本,則必須僅使用org.jxls org.jxls » jxls-poi » 2.11.0將使用apache poi 4.1.2工作。

但是您的代碼用於net.sf.jxls 所以這段代碼也需要修改。

請參閱http://jxls.sourceforge.net/getting_started.html了解如何使用org.jxls編寫代碼。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM