package com.logistic.common.utils.poi;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import org.apache.poi.hssf.usermodel.HSSFDateUtil;
import org.apache.poi.ss.usermodel.BorderStyle;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.DataValidation;
import org.apache.poi.ss.usermodel.DataValidationConstraint;
import org.apache.poi.ss.usermodel.DataValidationHelper;
import org.apache.poi.ss.usermodel.DateUtil;
import org.apache.poi.ss.usermodel.FillPatternType;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.apache.poi.ss.usermodel.IndexedColors;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.VerticalAlignment;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;
import org.apache.poi.ss.util.CellRangeAddressList;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFDataValidation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.logistic.common.core.text.Convert;
import com.logistic.common.exception.CustomException;
import com.logistic.common.utils.DateUtils;
import com.logistic.common.utils.StringUtils;
import com.logistic.common.utils.reflect.ReflectUtils;
import com.logistic.framework.aspectj.lang.annotation.Excel;
import com.logistic.framework.aspectj.lang.annotation.Excels;
import com.logistic.framework.aspectj.lang.annotation.Excel.ColumnType;
import com.logistic.framework.aspectj.lang.annotation.Excel.Type;
import com.logistic.framework.config.RuoYiConfig;
import com.logistic.framework.web.domain.AjaxResult;
/**
* Excel相关处理
*
* @author ruoyi
*/
public class ExcelUtil<T>
{
private static final Logger log = LoggerFactory.getLogger(ExcelUtil.class);
/**
* Excel sheet最大行数,默认65536
*/
public static final int sheetSize = 65536;
/**
* 工作表名称
*/
private String sheetName;
/**
* 导出类型(EXPORT:导出数据;IMPORT:导入模板)
*/
private Type type;
/**
* 工作薄对象
*/
private Workbook wb;
/**
* 工作表对象
*/
private Sheet sheet;
/**
* 样式列表
*/
private Map<String, CellStyle> styles;
/**
* 导入导出数据列表
*/
private List<T> list;
/**
* 注解列表
*/
private List<Object[]> fields;
/**
* 实体对象
*/
public Class<T> clazz;
public ExcelUtil(Class<T> clazz)
{
this.clazz = clazz;
}
public void init(List<T> list, String sheetName, Type type)
{
if (list == null)
{
list = new ArrayList<T>();
}
this.list = list;
this.sheetName = sheetName;
this.type = type;
createExcelField();
createWorkbook();
}
/**
* 对excel表单默认第一个索引名转换成list
*
* @param is 输入流
* @return 转换后集合
*/
public List<T> importExcel(InputStream is) throws Exception
{
return importExcel(StringUtils.EMPTY, is);
}
/**
* 对excel表单指定表格索引名转换成list
*
* @param sheetName 表格索引名
* @param is 输入流
* @return 转换后集合
*/
public List<T> importExcel(String sheetName, InputStream is) throws Exception
{
this.type = Type.IMPORT;
this.wb = WorkbookFactory.create(is);
List<T> list = new ArrayList<T>();
Sheet sheet = null;
if (StringUtils.isNotEmpty(sheetName))
{
// 如果指定sheet名,则取指定sheet中的内容.
sheet = wb.getSheet(sheetName);
}
else
{
// 如果传入的sheet名不存在则默认指向第1个sheet.
sheet = wb.getSheetAt(0);
}
if (sheet == null)
{
throw new IOException("文件sheet不存在");
}
int rows = sheet.getPhysicalNumberOfRows();
if (rows > 0)
{
// 定义一个map用于存放excel列的序号和field.
Map<String, Integer> cellMap = new HashMap<String, Integer>();
// 获取表头
Row heard = sheet.getRow(0);
for (int i = 0; i < heard.getPhysicalNumberOfCells(); i++)
{
Cell cell = heard.getCell(i);
if (StringUtils.isNotNull(cell != null))
{
String value = this.getCellValue(heard, i).toString();
cellMap.put(value, i);
}
else
{
cellMap.put(null, i);
}
}
// 有数据时才处理 得到类的所有field.
Field[] allFields = clazz.getDeclaredFields();
// 定义一个map用于存放列的序号和field.
Map<Integer, Field> fieldsMap = new HashMap<Integer, Field>();
for (int col = 0; col < allFields.length; col++)
{
Field field = allFields[col];
Excel attr = field.getAnnotation(Excel.class);
if (attr != null && (attr.type() == Type.ALL || attr.type() == type))
{
// 设置类的私有字段属性可访问.
field.setAccessible(true);
Integer column = cellMap.get(attr.name());
fieldsMap.put(column, field);
}
}
for (int i = 1; i < rows; i++)
{
// 从第2行开始取数据,默认第一行是表头.
Row row = sheet.getRow(i);
T entity = null;
for (Map.Entry<Integer, Field> entry : fieldsMap.entrySet())
{
Object val = this.getCellValue(row, entry.getKey());
// 如果不存在实例则新建.
entity = (entity == null ? clazz.newInstance() : entity);
// 从map中得到对应列的field.
Field field = fieldsMap.get(entry.getKey());
// 取得类型,并根据对象类型设置值.
Class<?> fieldType = field.getType();
if (String.class == fieldType)
{
String s = Convert.toStr(val);
if (StringUtils.endsWith(s, ".0"))
{
val = StringUtils.substringBefore(s, ".0");
}
else
{
val = Convert.toStr(val);
}
}
else if ((Integer.TYPE == fieldType) || (Integer.class == fieldType))
{
val = Convert.toInt(val);
}
else if ((Long.TYPE == fieldType) || (Long.class == fieldType))
{
val = Convert.toLong(val);
}
else if ((Double.TYPE == fieldType) || (Double.class
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
程序开发软件: Eclipse/Idea + Vscode + Mysql + Redis 采用技术: Springboot + Vue + ElementUI 本系统实现一个物流管理系统。具体功能描述如下: 1.系统其它信息管理:主要是针对系统的其他的信息进行管理,实现了系统的模块化的管理,系统的框架建设等信息的管理,具有系统的整合性功能的建立,支撑起整个系统的平台建设。 2.采购管理:系统采购管理,是本平台的一个初始化工作的登记,通过系统用户的用料商品的采购,进行登记管理,能够让平台最初的信息登记做到信息化的统计,方便用户在后期对采购商品的查看管理。 3.库存管理:库存管理主要是针对采购的物料信息进行入库和出库的管理,方便了用户对物料的登记管理。 4.供应商管理:供应商信息的管理和登记,通过供应商信息的登记,能够方便企业对供应商的查找,快速进货。 5.配送运输:配送运输是物流管理平台管理物流信息的一个重要的功能点,通过配送运输机制的建立,就能更好地对物流信息进行管理,进行物流信息一体化的建设工作。 6.出库入库管理:出库入库的信息管理,7.单据查询
资源推荐
资源详情
资源评论
收起资源包目录
基于Springboot+Vue+ElementUI物流配送管理系统 (1000个子文件)
package.bat 164B
build.bat 120B
run-web.bat 110B
ExcelUtil.class 25KB
Convert.class 14KB
HTMLFilter.class 14KB
SysMenuServiceImpl.class 11KB
SysUserServiceImpl.class 11KB
GenTableServiceImpl.class 11KB
ReflectUtils.class 11KB
SysDeptServiceImpl.class 9KB
SysUserController.class 9KB
VelocityUtils.class 8KB
Server.class 8KB
SysUser.class 8KB
HttpUtils.class 8KB
LogAspect.class 8KB
RedisCache.class 8KB
SysRoleServiceImpl.class 7KB
GenTableColumn.class 7KB
GenController.class 7KB
SecurityConfig.class 7KB
TokenService.class 7KB
StringUtils.class 7KB
UUID.class 6KB
VerifyCodeUtils.class 6KB
GenTable.class 6KB
FileUploadUtils.class 6KB
SysRoleController.class 6KB
SysMenuController.class 6KB
SysJobServiceImpl.class 6KB
GenUtils.class 6KB
MyBatisConfig.class 6KB
SysMenu.class 5KB
SysPostController.class 5KB
SysDictTypeController.class 5KB
SysConfigController.class 5KB
JobInvokeUtil.class 5KB
SysOperLog.class 5KB
SwaggerConfig.class 5KB
SysDeptController.class 5KB
SysProfileController.class 5KB
DataScopeAspect.class 5KB
GlobalExceptionHandler.class 5KB
ScheduleUtils.class 5KB
BusGoods.class 5KB
BusOutportController.class 5KB
SysRole.class 5KB
SysJobController.class 5KB
SysDept.class 5KB
CommonController.class 5KB
SysJob.class 5KB
SysDictDataController.class 5KB
SysDictData.class 5KB
DruidConfig.class 5KB
ShippingdocController.class 5KB
BusDeliveryController.class 5KB
BusPurchaseInfoController.class 5KB
BusInportController.class 5KB
CaigouOrderInfoController.class 5KB
SysUserOnlineController.class 5KB
Base64.class 4KB
BusCustomorderController.class 4KB
BusGoodsController.class 4KB
BusPurchaseController.class 4KB
BusProviderController.class 4KB
BusCustomerController.class 4KB
BusCkCheckController.class 4KB
BusCaigouOrderController.class 4KB
BusRukuController.class 4KB
MaterialScrapController.class 4KB
BusOutport.class 4KB
TestController.class 4KB
BusCustomer.class 4KB
AbstractQuartzJob.class 4KB
SameUrlDataInterceptor.class 4KB
PermissionService.class 4KB
LoginUser.class 4KB
BusProvider.class 4KB
SysNoticeController.class 4KB
SysPostServiceImpl.class 4KB
SysJobLogController.class 4KB
DateUtils.class 4KB
SysLoginController.class 4KB
SysLoginService.class 4KB
IpUtils.class 4KB
SysPost.class 4KB
XssFilter.class 4KB
SysConfig.class 4KB
ServletUtils.class 4KB
TreeSelect.class 4KB
BusInport.class 4KB
SysJobLog.class 3KB
SysLogininforController.class 3KB
SysOperlogController.class 3KB
SysDictTypeServiceImpl.class 3KB
MaterialScrap.class 3KB
FastJson2JsonRedisSerializer.class 3KB
SysConfigServiceImpl.class 3KB
SysLogininfor.class 3KB
共 1000 条
- 1
- 2
- 3
- 4
- 5
- 6
- 10
资源评论
- 我是奇宝2023-06-23资源有很好的参考价值,总算找到了自己需要的资源啦。
初尘屿风
- 粉丝: 3602
- 资源: 278
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功