java.lang.NoSuchMethodError:org.apache.poi.hssf.usermodel.HSSFSheet.addMergedRegion

时间:2015-06-12 10:59:28

标签: java

您好我正在尝试使用poi合并单元格。我的poi-3.5-FINAL.jar中有web-inf/lib,但我仍然收到以下错误:

context with path [/OFSAA80] threw exception [javax.servlet.ServletException: java.lang.NoSuchMethodError: org.apache.poi.hssf.usermodel.HSSFSheet.addMergedRegion(Lorg/apache/poi/hssf/util/Region;)I] with root cause
 java.lang.NoSuchMethodError: org.apache.poi.hssf.usermodel.HSSFSheet.addMergedRegion(Lorg/apache/poi/hssf/util/Region;)I
    at com.sample.Template.generateTemplate(Template.java:108)
    at org.apache.jsp.template_jsp._jspService(template_jsp.java:100)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:725)

我的代码:

 HSSFRow mergedRow= sheet.createRow((short) 0);                        //Creating Report Header
 sheet.addMergedRegion(new Region(0, (short) 0, 0, (short)  4));
 HSSFCell mergedCell= mergedRow.createCell((short) 0);
 mergedCell.setCellValue(RRRConstants.REPORT_HEADER+selsch+"- "+scheduleName); 

2 个答案:

答案 0 :(得分:1)

您的版本似乎很旧,下载最新版本的JAR,您可以从这里开始:

http://central.maven.org/maven2/org/apache/poi/poi/3.12/poi-3.12.jar

答案 1 :(得分:0)

您要传递addMergedRegion org.apache.poi.hssf.util.RegionAPI中的方法(已弃用)签名,您应发送org.apache.poi.ss.util.Region以避免此错误。 ..

我强烈建议下载上一版本并使用新方法addMergedRegion

public int addMergedRegion(CellRangeAddress region)

旧版已被弃用:

  

已过时。
  (2008年8月)使用CellRangeAddress代替Region