diff --git a/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/export/template/ExcelExportOfTemplateUtil.java b/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/export/template/ExcelExportOfTemplateUtil.java index 83bd91b..093a131 100644 --- a/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/export/template/ExcelExportOfTemplateUtil.java +++ b/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/export/template/ExcelExportOfTemplateUtil.java @@ -215,7 +215,7 @@ public final class ExcelExportOfTemplateUtil extends BaseExportService { public Workbook createExcleByTemplate(TemplateExportParams params, Class pojoClass, Collection dataSet, Map map) { // step 1. 判断模板的地址 - if (params == null || map == null || (StringUtils.isEmpty(params.getTemplateUrl()) || params.getTemplateWb() == null)) { + if (params == null || map == null || (StringUtils.isEmpty(params.getTemplateUrl()) && params.getTemplateWb() == null)) { throw new ExcelExportException(ExcelExportEnum.PARAMETER_ERROR); } Workbook wb = null; diff --git a/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/imports/base/ImportBaseService.java b/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/imports/base/ImportBaseService.java index 53a7a33..fe52d46 100644 --- a/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/imports/base/ImportBaseService.java +++ b/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/imports/base/ImportBaseService.java @@ -1,12 +1,12 @@ /** * Copyright 2013-2015 JueYue (qrb.jueyue@gmail.com) - * + *

* Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + *

* http://www.apache.org/licenses/LICENSE-2.0 - * + *

* Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -15,26 +15,6 @@ */ package cn.afterturn.easypoi.excel.imports.base; -import java.io.File; -import java.io.FileOutputStream; -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.lang.reflect.ParameterizedType; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Date; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import cn.afterturn.easypoi.handler.inter.IExcelI18nHandler; -import org.apache.commons.lang3.StringUtils; -import org.apache.commons.lang3.builder.ReflectionToStringBuilder; -import org.apache.poi.ss.usermodel.Workbook; -import org.apache.poi.util.IOUtils; - import cn.afterturn.easypoi.excel.annotation.Excel; import cn.afterturn.easypoi.excel.annotation.ExcelCollection; import cn.afterturn.easypoi.excel.annotation.ExcelEntity; @@ -43,8 +23,21 @@ import cn.afterturn.easypoi.excel.entity.params.ExcelCollectionParams; import cn.afterturn.easypoi.excel.entity.params.ExcelImportEntity; import cn.afterturn.easypoi.exception.excel.ExcelImportException; import cn.afterturn.easypoi.exception.excel.enums.ExcelImportEnum; +import cn.afterturn.easypoi.handler.inter.IExcelI18nHandler; import cn.afterturn.easypoi.util.PoiPublicUtil; import cn.afterturn.easypoi.util.PoiReflectorUtil; +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.builder.ReflectionToStringBuilder; +import org.apache.poi.ss.usermodel.Workbook; +import org.apache.poi.util.IOUtils; + +import java.io.File; +import java.io.FileOutputStream; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.lang.reflect.ParameterizedType; +import java.text.SimpleDateFormat; +import java.util.*; /** * 导入基础和,普通方法和Sax共用 @@ -85,7 +78,7 @@ public class ImportBaseService { if (StringUtils.isNoneEmpty(excel.groupName())) { excelEntity.setName(excel.groupName() + "_" + excelEntity.getName()); } - if(excelEntityAnn != null && excelEntityAnn.show()){ + if (excelEntityAnn != null && excelEntityAnn.show()) { excelEntity.setName(excelEntityAnn.name() + "_" + excelEntity.getName()); } if (i18nHandler != null) { @@ -105,8 +98,8 @@ public class ImportBaseService { newMethods.add(excelEntity.getMethod()); excelEntity.setMethods(newMethods); } - if(excelEntity.getFixedIndex() != -1){ - temp.put("FIXED_"+excelEntity.getFixedIndex() , excelEntity); + if (excelEntity.getFixedIndex() != -1) { + temp.put("FIXED_" + excelEntity.getFixedIndex(), excelEntity); } else { temp.put(excelEntity.getName(), excelEntity); } @@ -184,7 +177,6 @@ public class ImportBaseService { } - public void getExcelFieldList(String targetId, Field[] fields, Class pojoClass, Map temp, List getMethods) throws Exception { @@ -271,6 +263,10 @@ public class ImportBaseService { * @throws Exception */ public void setValues(ExcelImportEntity entity, Object object, Object value) throws Exception { + // 去掉非包装类的异常情况 + if (value == null) { + return; + } if (entity.getMethods() != null) { setFieldBySomeMethod(entity.getMethods(), object, value); } else { diff --git a/easypoi-base/src/main/java/cn/afterturn/easypoi/util/PoiCellUtil.java b/easypoi-base/src/main/java/cn/afterturn/easypoi/util/PoiCellUtil.java index 2f8c364..b7d737d 100644 --- a/easypoi-base/src/main/java/cn/afterturn/easypoi/util/PoiCellUtil.java +++ b/easypoi-base/src/main/java/cn/afterturn/easypoi/util/PoiCellUtil.java @@ -1,5 +1,5 @@ /** - * + * */ package cn.afterturn.easypoi.util; @@ -11,14 +11,15 @@ import org.apache.poi.ss.util.CellRangeAddress; /** * @author xfworld - * @since 2015-12-28 * @version 1.0 * @see cn.afterturn.easypoi.util.PoiCellUtil * 获取单元格的值 + * @since 2015-12-28 */ public class PoiCellUtil { /** * 读取单元格的值 + * * @param sheet * @param row * @param column @@ -36,12 +37,13 @@ public class PoiCellUtil { return value; } - /** - * 获取合并单元格的值 - * @param sheet - * @param row - * @param column - * @return + /** + * 获取合并单元格的值 + * + * @param sheet + * @param row + * @param column + * @return */ public static String getMergedRegionValue(Sheet sheet, int row, int column) { int sheetMergeCount = sheet.getNumMergedRegions(); @@ -67,12 +69,13 @@ public class PoiCellUtil { return null; } - /** - * 判断指定的单元格是否是合并单元格 - * @param sheet - * @param row - * @param column - * @return + /** + * 判断指定的单元格是否是合并单元格 + * + * @param sheet + * @param row + * @param column + * @return */ public static boolean isMergedRegion(Sheet sheet, int row, int column) { int sheetMergeCount = sheet.getNumMergedRegions(); @@ -95,10 +98,11 @@ public class PoiCellUtil { return false; } - /** - * 获取单元格的值 - * @param cell - * @return + /** + * 获取单元格的值 + * + * @param cell + * @return */ public static String getCellValue(Cell cell) { if (cell == null) { @@ -115,7 +119,11 @@ public class PoiCellUtil { } else if (cell.getCellType() == CellType.FORMULA) { - return cell.getStringCellValue(); + try { + return cell.getCellFormula(); + } catch (Exception e) { + return String.valueOf(cell.getNumericCellValue()); + } } else if (cell.getCellType() == CellType.NUMERIC) {