package com.h.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.lang.reflect.ParameterizedType;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.RegExUtils;
import org.apache.commons.lang3.reflect.FieldUtils;
import org.apache.poi.hssf.usermodel.HSSFClientAnchor;
import org.apache.poi.hssf.usermodel.HSSFPicture;
import org.apache.poi.hssf.usermodel.HSSFPictureData;
import org.apache.poi.hssf.usermodel.HSSFShape;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ooxml.POIXMLDocumentPart;
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.ClientAnchor;
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.Drawing;
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.Name;
import org.apache.poi.ss.usermodel.PictureData;
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.CellRangeAddress;
import org.apache.poi.ss.util.CellRangeAddressList;
import org.apache.poi.util.IOUtils;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFClientAnchor;
import org.apache.poi.xssf.usermodel.XSSFDataValidation;
import org.apache.poi.xssf.usermodel.XSSFDrawing;
import org.apache.poi.xssf.usermodel.XSSFPicture;
import org.apache.poi.xssf.usermodel.XSSFShape;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTMarker;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.h.common.annotation.Excel;
import com.h.common.annotation.Excel.ColumnType;
import com.h.common.annotation.Excel.Type;
import com.h.common.annotation.Excels;
import com.h.common.config.RuoYiConfig;
import com.h.common.core.domain.AjaxResult;
import com.h.common.core.text.Convert;
import com.h.common.exception.UtilException;
import com.h.common.utils.DateUtils;
import com.h.common.utils.DictUtils;
import com.h.common.utils.StringUtils;
import com.h.common.utils.file.FileTypeUtils;
import com.h.common.utils.file.FileUtils;
import com.h.common.utils.file.ImageUtils;
import com.h.common.utils.reflect.ReflectUtils;
/**
* Excel相关处理
*
* @author ruoyi
*/
public class ExcelUtil<T>
{
private static final Logger log = LoggerFactory.getLogger(ExcelUtil.class);
public static final String FORMULA_REGEX_STR = "=|-|\\+|@";
public static final String[] FORMULA_STR = { "=", "-", "+", "@" };
/**
* 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;
/**
* 当前行号
*/
private int rownum;
/**
* 标题
*/
private String title;
/**
* 最大高度
*/
private short maxHeight;
/**
* 合并后最后行数
*/
private int subMergedLastRowNum = 0;
/**
* 合并后开始行数
*/
private int subMergedFirstRowNum = 1;
/**
* 对象的子列表方法
*/
private Method subMethod;
/**
* 对象的子列表属性
*/
private List<Field> subFields;
/**
* 统计列表
*/
private Map<Integer, Double> statistics = new HashMap<Integer, Double>();
/**
* 数字格式
*/
private static final DecimalFormat DOUBLE_FORMAT = new DecimalFormat("######0.00");
/**
* 实体对象
*/
public Class<T> clazz;
/**
* 需要排除列属性
*/
public String[] excludeFields;
public ExcelUtil(Class<T> clazz)
{
this.clazz = clazz;
}
/**
* 隐藏Excel中列属性
*
* @param fields 列属性名 示例[单个"name"/多个"id","name"]
* @throws Exception
*/
public void hideColumn(String... fields)
{
this.excludeFields = fields;
}
public void init(List<T> list, String sheetName, String title, Type type)
{
if (list == null)
{
list = new ArrayList<T>();
}
this.list = list;
this.sheetName = sheetName;
this.type = type;
this.title = title;
createExcelField();
createWorkbook();
createTitle();
createSubHead();
}
/**
* 创建excel第一行标题
*/
public void createTitle()
{
if (StringUtils.isNotEmpty(title))
{
subMergedFirstRowNum++;
subMergedLastRowNum++;
int titleLastCol = this.fields.size() - 1;
if (isSubList())
{
titleLastCol = titleLastCol + subFields.size() - 1;
}
Row titleRow = sheet.createRow(rownum == 0 ? rownum++ : 0);
titleRow.setHeightInPoints(30);
Cell titleCell = titleRow.createCell(0);
titleCell.setCellStyle(styles.get("title"));
titleCell.setCellValue(title);
sheet.addMergedRegion(new CellRangeAddress(titleRow.getRowNum(), titleRow.getRowNum(), titleRow.getRowNum(), titleLastCol));
}
}
/**
* 创建对象的子列表名称
*/
public void createSubHead()
{
if (isSubList())
{
subMergedFirstRowNum++;
subMergedLastRowNum++;
Row subRow = sheet.createRow(rownum);
int excelNum = 0;
for (Object[] objects : fields)
{
Excel attr = (Excel) objects[1];
Cell headCell1 = subRow.createCell(excelNum);
headCell1.setCellValue(attr.name());
headCell1.setCellStyle(styles.get(StringUtils.format("header_{}_{}", attr.headerColor(), attr.headerBackgroundColor())));
excelNum++;
}
int headFirstRow = excelNum - 1;
int headLastRow = headFirstRow + subFields.size() - 1;
if (headLastRow > headFirstRow)
{
sheet.addMergedRegion(new CellRangeAddress(rownum, rownum, headFirstRow, headLastRow));
}
rownum++;
}
}
/**
* 对excel表单默认第一个索引名转换成li
没有合适的资源?快使用搜索试试~ 我知道了~
基于SpringBoot+Websocket+Vue的仿微信即时通讯系统源码+数据库sql(课程大作业).zip
共790个文件
java:264个
vue:113个
gif:101个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 167 浏览量
2023-12-17
23:19:59
上传
评论 2
收藏 7.19MB ZIP 举报
温馨提示
【项目说明】 1.项目代码均经过功能验证ok,确保稳定可靠运行。欢迎下载食用体验! 2.主要针对各个计算机相关专业,包括计算机科学、信息安全、数据科学与大数据技术、人工智能、通信、物联网等领域的在校学生、专业教师、企业员工。 3.项目具有丰富的拓展空间,不仅可作为入门进阶,也可直接作为毕设、课程设计、大作业、初期项目立项演示等用途。 4.当然也鼓励大家基于此进行二次开发。在使用过程中,如有问题或建议,请及时沟通。 5.期待你能在项目中找到乐趣和灵感,也欢迎你的分享和反馈! 【资源介绍】 基于SpringBoot+Websocket+Vue的仿微信即时通讯系统源码+数据库sql(课程大作业).zip基于SpringBoot+Websocket+Vue的仿微信即时通讯系统源码+数据库sql(课程大作业).zip基于SpringBoot+Websocket+Vue的仿微信即时通讯系统源码+数据库sql(课程大作业).zip基于SpringBoot+Websocket+Vue的仿微信即时通讯系统源码+数据库sql(课程大作业).zip 基于SpringBoot+Websocket+Vue的仿微信即时通讯系统源码+数据库sql(课程大作业).zip 基于SpringBoot+Websocket+Vue的仿微信即时通讯系统源码+数据库sql(课程大作业).zip
资源推荐
资源详情
资源评论
收起资源包目录
基于SpringBoot+Websocket+Vue的仿微信即时通讯系统源码+数据库sql(课程大作业).zip (790个子文件)
package.bat 152B
build.bat 109B
run-web.bat 107B
com.anji.captcha.service.CaptchaCacheService 48B
normalize.css 6KB
global.css 2KB
iconfont.css 917B
.env.development 215B
.editorconfig 514B
iconfont.eot 6KB
.eslintignore 298B
401.gif 160KB
142.gif 12KB
135.gif 12KB
140.gif 10KB
111.gif 8KB
119.gif 7KB
118.gif 7KB
132.gif 7KB
149.gif 6KB
131.gif 5KB
197.gif 5KB
129.gif 5KB
157.gif 5KB
146.gif 5KB
108.gif 5KB
168.gif 4KB
145.gif 4KB
133.gif 4KB
143.gif 4KB
126.gif 4KB
107.gif 4KB
114.gif 4KB
151.gif 4KB
147.gif 4KB
172.gif 4KB
110.gif 4KB
194.gif 3KB
106.gif 3KB
184.gif 3KB
141.gif 3KB
128.gif 3KB
109.gif 3KB
150.gif 3KB
195.gif 3KB
117.gif 3KB
122.gif 3KB
160.gif 3KB
158.gif 2KB
167.gif 2KB
127.gif 2KB
190.gif 2KB
155.gif 2KB
189.gif 2KB
125.gif 2KB
174.gif 2KB
154.gif 2KB
124.gif 2KB
112.gif 2KB
173.gif 2KB
199.gif 2KB
134.gif 2KB
188.gif 2KB
153.gif 2KB
104.gif 2KB
123.gif 2KB
121.gif 2KB
105.gif 2KB
103.gif 2KB
100.gif 2KB
196.gif 2KB
102.gif 2KB
120.gif 2KB
139.gif 2KB
130.gif 2KB
148.gif 2KB
138.gif 2KB
113.gif 2KB
198.gif 2KB
181.gif 2KB
183.gif 2KB
185.gif 2KB
178.gif 2KB
182.gif 2KB
187.gif 2KB
180.gif 2KB
101.gif 1KB
159.gif 1KB
144.gif 1KB
115.gif 1KB
186.gif 1KB
179.gif 1KB
152.gif 1KB
136.gif 1KB
192.gif 1KB
116.gif 1KB
165.gif 1KB
162.gif 1KB
175.gif 1KB
137.gif 1KB
共 790 条
- 1
- 2
- 3
- 4
- 5
- 6
- 8
资源评论
北航程序员小C
- 粉丝: 2222
- 资源: 1823
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功