package com.zhaoxinms.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.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.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.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.zhaoxinms.common.annotation.Excel;
import com.zhaoxinms.common.annotation.Excels;
import com.zhaoxinms.common.annotation.Excel.ColumnType;
import com.zhaoxinms.common.annotation.Excel.Type;
import com.zhaoxinms.common.config.RuoYiConfig;
import com.zhaoxinms.common.core.domain.AjaxResult;
import com.zhaoxinms.common.core.text.Convert;
import com.zhaoxinms.common.exception.UtilException;
import com.zhaoxinms.common.utils.DateUtils;
import com.zhaoxinms.common.utils.DictUtils;
import com.zhaoxinms.common.utils.StringUtils;
import com.zhaoxinms.common.utils.file.FileTypeUtils;
import com.zhaoxinms.common.utils.file.FileUtils;
import com.zhaoxinms.common.utils.file.ImageUtils;
import com.zhaoxinms.common.utils.reflect.ReflectUtils;
/**
* 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;
/**
* 当前行号
*/
private int rownum;
/**
* 标题
*/
private String title;
/**
* 最大高度
*/
private short maxHeight;
/**
* 统计列表
*/
private Map<Integer, Double> statistics = new HashMap<Integer, Double>();
/**
* 数字格式
*/
private static final DecimalFormat DOUBLE_FORMAT = new DecimalFormat("######0.00");
/**
* 实体对象
*/
public Class<T> clazz;
public ExcelUtil(Class<T> clazz)
{
this.clazz = clazz;
}
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();
}
/**
* 创建excel第一行标题
*/
public void createTitle()
{
if (StringUtils.isNotEmpty(title))
{
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(),
this.fields.size() - 1));
}
}
/**
* 对excel表单默认第一个索引名转换成list
*
* @param is 输入流
* @return 转换后集合
*/
public List<T> importExcel(InputStream is) throws Exception
{
return importExcel(is, 0);
}
/**
* 对excel表单默认第一个索引名转换成list
*
* @param is 输入流
* @param titleNum 标题占用行数
* @return 转换后集合
*/
public List<T> importExcel(InputStream is, int titleNum) throws Exception
{
return importExcel(StringUtils.EMPTY, is, titleNum);
}
/**
* 对excel表单指定表格索引名转换成list
*
* @param sheetName 表格索引名
* @param titleNum 标题占用行数
* @param is 输入流
* @return 转换后集合
*/
public List<T> importExcel(String sheetName, InputStream is, int titleNum) throws Exception
{
this.type = Type.IMPORT;
this.wb = WorkbookFactory.create(is);
List<T> list = new ArrayList<T>();
// 如果指定sheet名,则取指定sheet中的内容 否则默认指向第1个sheet
Sheet sheet = StringUtils.isNotEmpty(sheetName) ? wb.getSheet(sheetName) : wb.getSheetAt(0);
if (sheet == null)
{
throw new IOException("文件sheet不存在");
}
boolean isXSSFWorkbook = !(wb instanceof HSSFWorkbook);
Map<String, PictureData> pictures;
if (isXSSFWorkbook)
{
pictures = getSheetPictures07((XSSFSheet) sheet, (XSSFWorkbook) wb);
}
else
{
pictures = getSheetPictures03((HSSFSheet) sheet, (HSSFWorkbook) wb);
}
// 获取最后一个非空行的行下标,比如总行数为n,则返回的为n-1
int rows = sheet.getLastRowNum();
if (rows > 0)
{
// 定义一个map用于存放excel列的序号和field.
Map<String, Integer> cellMap = new HashMap<String, Integer>();
// 获取表头
Row heard = sheet.getRow(titleNum);
for (int i = 0; i < heard.getPhysicalNumberOfCells(); i++)
{
Cell cell = heard.getCell(i);
if (StringUtils.isNotNull(cell))
{
String value
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
本肇新智慧物业管理系统基于Java和Vue开发,包含1628个文件,包括Java源代码、Vue组件、JavaScript脚本、SVG图形、PNG图片、HTML页面、XLSX文件、XML配置文件、CSS样式表和VM虚拟机文件。系统实现了停车、安保、客服、工单、收费、财务、办公自动化等功能,界面友好,功能完善,适合用于构建软硬件一体的智慧物业解决方案。
资源推荐
资源详情
资源评论
收起资源包目录
基于Java和Vue的肇新智慧物业管理系统设计源码 (1628个子文件)
ry.bat 2KB
run.bat 269B
package.bat 185B
build.bat 142B
package.bat 141B
run-web.bat 139B
clean.bat 102B
CHANGES 3KB
bootstrap.css 118KB
iconfont.css 99KB
bootstrap.min.css 98KB
style-common.css 25KB
iconfont.css 18KB
bootstrap-theme.css 15KB
bootstrap-theme.min.css 13KB
style-editor.css 10KB
style.css 8KB
ng-grid-2.0.7.min.css 7KB
daterangepicker-bs3.css 5KB
editor.css 3KB
style.css 2KB
jasmine.css 2KB
.env.development 215B
.editorconfig 514B
iconfont.eot 292KB
iconfont.eot 77KB
glyphicons-halflings-regular.eot 20KB
glyphicons-halflings-regular.eot 20KB
activiti-admin-webfont.eot 5KB
.eslintignore 298B
CLodop_Setup_for_Win32NT.exe 4.62MB
401.gif 160KB
loading.gif 17KB
nw-handle-dark.gif 839B
se-handle-dark.gif 838B
.gitignore 629B
.gitignore 256B
.gitignore 23B
ie.html 23KB
event-listeners-popup.html 10KB
form-properties-popup.html 9KB
modeler.html 8KB
execution-listeners-popup.html 8KB
editor.html 8KB
index.html 7KB
task-listeners-popup.html 7KB
index.html 5KB
fields-popup.html 4KB
out-parameters-popup.html 3KB
in-parameters-popup.html 3KB
signal-definitions-popup.html 3KB
message-definitions-popup.html 2KB
subprocess-reference-popup.html 2KB
assignment-popup-popup.html 2KB
assignment-popup.html 2KB
sequenceflow-order-popup.html 2KB
save-model.html 2KB
index.html 2KB
index.min.html 2KB
assignment-candidateGroup.html 1KB
condition-expression-popup.html 1KB
stencil-item-template.html 1012B
unsaved-changes.html 977B
select-shape.html 811B
feedback-popup.html 798B
assignment-display-template.html 796B
text-popup.html 713B
root-stencil-item-template.html 463B
message-property-write-template.html 275B
signal-property-write-template.html 268B
string-property-write-mode-template.html 239B
multiinstance-property-write-template.html 232B
default-value-display-template.html 231B
execution-listeners-display-template.html 209B
event-listeners-display-template.html 197B
form-properties-display-template.html 195B
out-parameters-display-template.html 192B
task-listeners-display-template.html 192B
in-parameters-display-template.html 189B
message-definitions-display-template.html 189B
signal-definitions-display-template.html 188B
condition-expression-display-template.html 173B
fields-display-template.html 173B
subprocess-reference-display-template.html 172B
subprocess-reference-write-template.html 170B
sequenceflow-order-display-template.html 169B
condition-expression-write-template.html 161B
signal-definitions-write-template.html 161B
message-definitions-write-template.html 161B
execution-listeners-write-template.html 160B
sequenceflow-order-write-template.html 159B
event-listeners-write-template.html 156B
form-properties-write-template.html 156B
out-parameters-write-template.html 155B
task-listeners-write-template.html 155B
text-property-write-template.html 154B
in-parameters-write-template.html 154B
assignment-write-template.html 152B
fields-write-template.html 148B
boolean-property-template.html 136B
共 1628 条
- 1
- 2
- 3
- 4
- 5
- 6
- 17
资源评论
沐知全栈开发
- 粉丝: 4771
- 资源: 3372
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功