我尝试使用jxls库创建excel表单。
我的Excel模板是:
当我只是将一个地图添加到列表并绑定它时,它就可以了。 我的代码很简单:
List<Map<String,Object>> sss = new ArrayList();
HashMap<String,Object> sm = new HashMap<String,Object>();
sm.put("name1", "AtestName");
sm.put("name2", "AtestName2");
sm.put("name3", "AtestName3");
sss.add(sm);
Map<String, Object> model = new HashMap<String,Object>();
model.put("sData", sss);
.... XLSTransformer transformer = new XLSTransformer(); .....
但是当我将多个地图添加到列表并绑定它时,它无法抛出异常。 我听说jxls库自动识别列表。 我在做什么?
List<Map<String,Object>> sss = new ArrayList();
HashMap<String,Object> sm = new HashMap<String,Object>();
sm.put("name1", "AtestName");
sm.put("name2", "AtestName2");
sm.put("name3", "AtestName3");
sss.add(sm);
HashMap<String,Object> sm2 = new HashMap<String,Object>();
sm.put("name1", "BtestName");
sm.put("name2", "BtestName2");
sm.put("name3", "BtestName3");
sss.add(sm2);
HashMap<String,Object> sm3 = new HashMap<String,Object>();
sm.put("name1", "CtestName");
sm.put("name2", "CtestName2");
sm.put("name3", "CtestName3");
sss.add(sm3);
Map<String, Object> model = new HashMap<String,Object>();
model.put("sData", sss);
.... XLSTransformer transformer = new XLSTransformer(); .....
[ 06:15:10] DEBUG - AbstractExcelView.renderMergedOutputModel(140) | Created Excel Workbook from scratch
[ 06:15:10] DEBUG - SheetTransformer.transformSheet(72) | Processing sheet: Sheet1
[ 06:15:10] DEBUG - CollectionRowTransformer.processRowCollections(96) | ----collection-property--------->sData
, 2016 6:15:10 오후 org.apache.catalina.core.StandardWrapperValve invoke
: Servlet.service() for servlet action threw exception
java.lang.NoSuchMethodError: org.apache.poi.ss.usermodel.Sheet.getSheetConditionalFormatting()Lorg/apache/poi/ss/usermodel/SheetConditionalFormatting;
at net.sf.jxls.util.Util.copyConditionalFormat(Util.java:642)
at net.sf.jxls.util.Util.copyCell(Util.java:569)
at net.sf.jxls.util.Util.duplicateStyle(Util.java:411)
at net.sf.jxls.util.Util.duplicateRow(Util.java:244)
at net.sf.jxls.controller.SheetTransformationControllerImpl.duplicateRow(SheetTransformationControllerImpl.java:140)
at net.sf.jxls.transformer.CollectionRowTransformer.processRowCollections(CollectionRowTransformer.java:106)
at net.sf.jxls.transformer.CollectionRowTransformer.transform(CollectionRowTransformer.java:66)
at net.sf.jxls.transformer.SheetTransformer.transformSheet(SheetTransformer.java:88)
at net.sf.jxls.transformer.XLSTransformer.transformWorkbook(XLSTransformer.java:248)
at net.sf.jxls.transformer.XLSTransformer.transformXLS(XLSTransformer.java:221)
答案 0 :(得分:0)
您获得的错误java.lang.NoSuchMethodError:org.apache.poi.ss.usermodel.Sheet.getSheetConditionalFormatting
最有可能意味着POI版本存在问题。
因此,请检查您使用的Apache POI版本以及是否支持Sheet.getSheetConditionalFormatting()
方法