Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.修复getCell读取空行越界 2.获取图片增加类型判断 #126

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Copyright 2013-2015 JEECG ([email protected])
*
*
* 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
Expand Down Expand Up @@ -50,7 +50,7 @@

/**
* Excel 导入服务
*
*
* @author JEECG
* @date 2014年6月26日 下午9:20:51
*/
Expand Down Expand Up @@ -78,7 +78,7 @@ public ExcelImportServer() {

/***
* 向List里面继续添加元素
*
*
* @param object
* @param param
* @param row
Expand Down Expand Up @@ -114,7 +114,7 @@ private void addListContinue(Object object, ExcelCollectionParams param, Row row

/**
* 获取key的值,针对不同类型获取不同的值
*
*
* @Author JEECG
* @date 2013-11-21
* @param cell
Expand Down Expand Up @@ -144,7 +144,7 @@ private String getKeyValue(Cell cell) {

/**
* 获取保存的真实路径
*
*
* @param excelImportEntity
* @param object
* @return
Expand Down Expand Up @@ -208,12 +208,15 @@ private <T> List<T> importExcel(Collection<T> result, Sheet sheet, Class<?> pojo
for (ExcelCollectionParams param : excelCollection) {
addListContinue(object, param, row, titlemap, targetId, pictures, params);
}
} else {

} else {
object = PoiPublicUtil.createObject(pojoClass, targetId);
try {
//update-begin-author:taoyan date:20200303 for:导入图片
int firstCellNum = row.getFirstCellNum();
if(firstCellNum<0){
firstCellNum = 0;
}
if(firstCellNum>minColumnIndex){
firstCellNum = minColumnIndex;
}
Expand Down Expand Up @@ -314,7 +317,7 @@ private void ignoreHeaderHandler(Map<String, ExcelImportEntity> excelParams,Impo

/**
* 获取表格字段列名对应信息
*
*
* @param rows
* @param params
* @param excelCollection
Expand Down Expand Up @@ -352,7 +355,7 @@ private Map<Integer, String> getTitleMap(Sheet sheet, Iterator<Row> rows, Import
titlemap.put(cell.getColumnIndex(), value);//加入表头列表
}
}

//多行表头
for (int j = headBegin; j < headBegin + params.getHeadRows()-1; j++) {
headRow = sheet.getRow(j);
Expand Down Expand Up @@ -404,7 +407,7 @@ private Map<Integer, String> getTitleMap(Sheet sheet, Iterator<Row> rows, Import
//update-end--Author:xuelin Date:20171205 for:TASK #2098 【excel问题】 Online 一对多导入失败--------------------
/**
* 获取这个名称对应的集合信息
*
*
* @param excelCollection
* @param collectionName
* @return
Expand All @@ -420,7 +423,7 @@ private ExcelCollectionParams getCollectionParams(List<ExcelCollectionParams> ex

/**
* Excel 导入 field 字段类型 Integer,Long,Double,Date,String,Boolean
*
*
* @param inputstream
* @param pojoClass
* @param params
Expand Down Expand Up @@ -485,7 +488,7 @@ public ExcelImportResult importExcelByIs(InputStream inputstream, Class<?> pojoC
}
}
//update-end-author:taoyan date:2023-3-4 for: 导入数据支持指定sheet名称

if (LOGGER.isDebugEnabled()) {
LOGGER.debug(" start to read excel by is ,startTime is {}", System.currentTimeMillis());
}
Expand Down Expand Up @@ -534,7 +537,7 @@ public static byte[] getBytes(InputStream is) throws IOException {

/**
* 保存字段值(获取值,校验值,追加错误信息)
*
*
* @param params
* @param object
* @param cell
Expand Down Expand Up @@ -568,7 +571,7 @@ private Object saveFieldValue(ImportParams params, Object object, Cell cell, Map
}

/**
*
*
* @param object
* @param picId
* @param excelParams
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Copyright 2013-2015 JEECG ([email protected])
*
*
* 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
Expand Down Expand Up @@ -66,7 +66,7 @@

/**
* AutoPoi 的公共基础类
*
*
* @author JEECG
* @date 2015年4月5日 上午12:59:22
*/
Expand All @@ -89,7 +89,7 @@ public static <K, V> Map<K, V> mapFor(Object... mapping) {

/**
* 彻底创建一个对象
*
*
* @param clazz
* @return
*/
Expand Down Expand Up @@ -126,7 +126,7 @@ public static Object createObject(Class<?> clazz, String targetId) {

/**
* 获取class的 包括父类的
*
*
* @param clazz
* @return
*/
Expand Down Expand Up @@ -163,7 +163,7 @@ public static String getFileExtendName(byte[] photoByte) {

/**
* 获取GET方法
*
*
* @param name
* @param pojoClass
* @return
Expand All @@ -184,7 +184,7 @@ public static Method getMethod(String name, Class<?> pojoClass) throws Exception

/**
* 获取SET方法
*
*
* @param name
* @param pojoClass
* @param type
Expand All @@ -197,7 +197,7 @@ public static Method getMethod(String name, Class<?> pojoClass, Class<?> type) t
getMethodName.append(name.substring(1));
return pojoClass.getMethod(getMethodName.toString(), new Class[] { type });
}

//update-begin-author:taoyan date:20180615 for:TASK #2798 导入扩展方法,支持自定义导入字段转换规则
/**
* 获取get方法 通过EXCEL注解exportConvert判断是否支持值的转换
Expand All @@ -223,7 +223,7 @@ public static Method getMethod(String name, Class<?> pojoClass,boolean convert)
}
return method;
}

/**
* 获取set方法 通过EXCEL注解importConvert判断是否支持值的转换
* @param name
Expand All @@ -244,10 +244,10 @@ public static Method getMethod(String name, Class<?> pojoClass, Class<?> type,bo
return pojoClass.getMethod(setMethodName.toString(), new Class[] { type });
}
//update-end-author:taoyan date:20180615 for:TASK #2798 导入扩展方法,支持自定义导入字段转换规则

/**
* 获取Excel2003图片
*
*
* @param sheet
* 当前sheet对象
* @param workbook
Expand Down Expand Up @@ -276,7 +276,7 @@ public static Map<String, PictureData> getSheetPictrues03(HSSFSheet sheet, HSSFW

/**
* 获取Excel2007图片
*
*
* @param sheet
* 当前sheet对象
* @param workbook
Expand All @@ -290,11 +290,13 @@ public static Map<String, PictureData> getSheetPictrues07(XSSFSheet sheet, XSSFW
XSSFDrawing drawing = (XSSFDrawing) dr;
List<XSSFShape> shapes = drawing.getShapes();
for (XSSFShape shape : shapes) {
XSSFPicture pic = (XSSFPicture) shape;
XSSFClientAnchor anchor = pic.getPreferredSize();
CTMarker ctMarker = anchor.getFrom();
String picIndex = ctMarker.getRow() + "_" + ctMarker.getCol();
sheetIndexPicMap.put(picIndex, pic.getPictureData());
if (shape instanceof XSSFPicture) {
XSSFPicture pic = (XSSFPicture) shape;
XSSFClientAnchor anchor = pic.getPreferredSize();
CTMarker ctMarker = anchor.getFrom();
String picIndex = ctMarker.getRow() + "_" + ctMarker.getCol();
sheetIndexPicMap.put(picIndex, pic.getPictureData());
}
}
}
}
Expand Down Expand Up @@ -545,7 +547,7 @@ public static String getWebRootPath(String filePath) {

/**
* 判断是不是集合的实现类
*
*
* @param clazz
* @return
*/
Expand All @@ -555,7 +557,7 @@ public static boolean isCollection(Class<?> clazz) {

/**
* 是不是java基础类
*
*
* @param field
* @return
*/
Expand All @@ -578,7 +580,7 @@ public static boolean isJavaClass(Field field) {

/**
* 判断是否不要在这个excel操作中
*
*
* @param
* @param field
* @param targetId
Expand All @@ -600,7 +602,7 @@ public static boolean isNotUserExcelUserThis(List<String> exclusionsList, Field

/**
* 判断是不是使用
*
*
* @param exportName
* @param targetId
* @return
Expand All @@ -627,7 +629,7 @@ private static Integer getImageType(String type) {

/**
* 返回流和图片类型
*
*
* @Author JEECG
* @date 2013-11-20
* @param entity
Expand Down Expand Up @@ -659,7 +661,7 @@ public static Object[] getIsAndType(WordImageEntity entity) throws Exception {

/**
* 获取参数值
*
*
* @param params
* @param map
* @return
Expand All @@ -678,7 +680,7 @@ public static Object getParamsValue(String params, Object object) throws Excepti

/**
* 解析数据
*
*
* @Author JEECG
* @date 2013-11-16
* @return
Expand Down Expand Up @@ -707,7 +709,7 @@ public static Object getRealValue(String currentText, Map<String, Object> map) t

/**
* 通过遍历过去对象值
*
*
* @param object
* @param paramsArr
* @param index
Expand All @@ -732,7 +734,7 @@ public static Object getValueDoWhile(Object object, String[] paramsArr, int inde

/**
* double to String 防止科学计数法
*
*
* @param value
* @return
*/
Expand Down