瀏覽代碼

poi 4.0 excel导入导出修正版本

4.1.3.A
jueyue 6 年之前
父節點
當前提交
c2582b168e
共有 3 個文件被更改,包括 51 次插入47 次删除
  1. +1
    -1
      easypoi-base/src/main/java/cn/afterturn/easypoi/excel/export/template/ExcelExportOfTemplateUtil.java
  2. +23
    -27
      easypoi-base/src/main/java/cn/afterturn/easypoi/excel/imports/base/ImportBaseService.java
  3. +27
    -19
      easypoi-base/src/main/java/cn/afterturn/easypoi/util/PoiCellUtil.java

+ 1
- 1
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<String, Object> 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;


+ 23
- 27
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)
*
* <p>
* 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
*
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
*
* <p>
* 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<String, ExcelImportEntity> temp,
List<Method> 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 {


+ 27
- 19
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) {



Loading…
取消
儲存