package com.smart.common.util;
import com.smart.common.constant.ExcelDataType;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFRichTextString;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.ss.util.RegionUtil;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.apache.poi.xssf.usermodel.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.awt.*;
import java.awt.Color;
import java.io.*;
import java.net.URLEncoder;
import java.sql.Timestamp;
import java.util.List;
import java.util.*;
/**
* 导出Excel文件(导出“XLSX”格式,支持大数据量导出 @see org.apache.poi.ss.SpreadsheetVersion)
*/
public class ExcelExport {
private static Logger log = LoggerFactory.getLogger(ExcelExport.class);
/**
* 单元格靠左对齐
*/
public static final Integer CELL_ALIGN_LEFT = 1;
/**
* 单元格居中对齐
*/
public static final Integer CELL_ALIGN_CENTER = 2;
/**
* 单元格靠右对齐
*/
public static final Integer CELL_ALIGN_RIGHT = 3;
/**
* 工作薄对象
*/
private SXSSFWorkbook wb;
/**
* 工作表对象
*/
private Sheet sheet;
/**
* 样式列表
*/
private Map<String, CellStyle> styles;
/**
* 当前行号
*/
private int rownum;
/**
* 导出模板工作薄对象
*/
private Workbook workbook;
/**
* 构造函数
*
* 导出文件模板,读取第一个工作表
* @param headerNum
* 标题行号,数据行号=标题行号+1
* @throws InvalidFormatException
* @throws IOException
*/
public ExcelExport(String fileName, int headerNum) throws InvalidFormatException, IOException {
this(new File(fileName), headerNum);
}
/**
* 构造函数
*
* 导出文件模板对象,读取第一个工作表
* @param headerNum
* 标题行号,数据行号=标题行号+1
* @throws InvalidFormatException
* @throws IOException
*/
public ExcelExport(File file, int headerNum) throws InvalidFormatException, IOException {
this(file, headerNum, 0);
}
/**
* 构造函数
*
* 导出文件模板
* @param headerNum
* 标题行号,数据行号=标题行号+1
* @param sheetIndex
* 工作表编号
* @throws InvalidFormatException
* @throws IOException
*/
public ExcelExport(String fileName, int headerNum, int sheetIndex) throws InvalidFormatException, IOException {
this(new File(fileName), headerNum, sheetIndex);
}
/**
* 构造函数
*
* 导出文件模板对象
* @param headerNum
* 标题行号,数据行号=标题行号+1
* @param sheetIndex
* 工作表编号
* @throws InvalidFormatException
* @throws IOException
*/
public ExcelExport(File file, int headerNum, int sheetIndex) throws InvalidFormatException, IOException {
this(file.getName(), new FileInputStream(file), headerNum, sheetIndex);
}
/**
* 构造函数
*
* 导出文件模板对象
* @param headerNum
* 标题行号,数据行号=标题行号+1
* @param sheetIndex
* 工作表编号
* @throws IOException
*/
public ExcelExport(String fileName, InputStream is, int headerNum, int sheetIndex)
throws IOException {
if (StringUtils.isBlank(fileName)) {
throw new RuntimeException("导入文档为空!");
} else if (fileName.toLowerCase().endsWith("xls")) {
this.workbook = new HSSFWorkbook(is);
} else if (fileName.toLowerCase().endsWith("xlsx")) {
this.workbook = new XSSFWorkbook(is);
} else if (fileName.toLowerCase().endsWith("xlsm")) {
this.workbook = new XSSFWorkbook(is);
} else {
throw new RuntimeException("文档格式不正确!");
}
if (this.workbook.getNumberOfSheets() < sheetIndex) {
throw new RuntimeException("文档中没有工作表!");
}
this.sheet = this.workbook.getSheetAt(sheetIndex);
if (this.sheet.getLastRowNum() < 0) {
throw new RuntimeException("文档模板错误!");
}
this.rownum = headerNum + 1;
this.styles = createStyles(workbook);
log.debug("Initialize success.");
}
/**
* 构造函数 -- SXSSFWorkbook
* @param fileName
* @param headerNum
* @param sheetIndex
* @param batchType
* @throws IOException
*/
public ExcelExport(String fileName, int headerNum, int sheetIndex, String batchType)
throws IOException {
if (StringUtils.isBlank(fileName)) {
throw new RuntimeException("导出文档为空!");
} else {
InputStream is = new FileInputStream(new File(fileName));
XSSFWorkbook workb = new XSSFWorkbook(is);
this.wb = new SXSSFWorkbook(workb, 1000);
if (this.wb.getNumberOfSheets() < sheetIndex) {
throw new RuntimeException("文档中没有工作表!");
}
this.sheet = this.wb.getSheetAt(sheetIndex);
this.rownum = headerNum + 1;
this.styles = createStyles(wb);
log.debug("Initialize success.");
}
}
/**
* 构造函数
*
* @param title
* 表格标题,传“空值”,表示无标题
* @param headerMap
* 表头数组
*/
public ExcelExport(String title, Map<String, String> headerMap) {
List<String> headerList = new ArrayList<String>();
headerList.add("序号");
for (String key : headerMap.keySet()) {
headerList.add(headerMap.get(key));
}
initialize(title, headerList);
}
/**
* 构造函数
*
* @param title
* 表格标题,传“空值”,表示无标题
* @param headerList
* 表头列表
*/
public ExcelExport(String title, List<String> headerList) {
// 自动增加序号列
headerList.add(0, "序号");
initialize(title, headerList);
}
/**
* 初始化函数
*
* @param title
* 表格标题,传“空值”,表示无标题
* @param headerList
* 表头列表
*/
private void initialize(String title, List<String> headerList) {
this.wb = new SXSSFWorkbook(500);
this.sheet = wb.createSheet("Export");
this.styles = createStyles(wb);
// Create title
if (StringUtils.isNotBlank(title)) {
Row titleRow = sheet.createRow(rownum++);
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(),
headerList.size() - 1));
}
// Create header
if (headerList == null) {
throw new RuntimeException("headerList not null!");
}
Row headerRow = sheet.createRow(rownum++);
headerRow.setHeightInPoints(16);
for (int i = 0; i < headerList.size(); i++) {
Cell cell = headerRow.createCell(i);
cell.setCellSty
没有合适的资源?快使用搜索试试~ 我知道了~
基于SpringBoot + Vue 的智能停车场平台程序设计
共1092个文件
js:276个
gif:164个
png:130个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
5星 · 超过95%的资源 4 下载量 16 浏览量
2022-03-15
18:41:42
上传
评论 12
收藏 14.34MB ZIP 举报
温馨提示
基于SpringBoot + Vue 的智能停车场平台程序设计 1.简介系统管理:角色管理、接口管理、系统菜单、全局配置;账号管理:用户管理、合作单位;系统监控:监控大屏、日志监控;财务管理:订单列表; 停车记录:停车记录;车辆管理:车辆管理;车牌识别:车牌识别;停车场管理:停车场管理等功能 2.环境:【SpringBoot】SpringBoot + SpringMVC + SpringDataJPA + Vue + Thymeleaf 3. 详文链接:https://mryang.blog.csdn.net/article/details/123508099
资源推荐
资源详情
资源评论
收起资源包目录
基于SpringBoot + Vue 的智能停车场平台程序设计 (1092个子文件)
ExcelExport.class 33KB
ExcelImport.class 14KB
SysUser.class 11KB
CarManage.class 10KB
SysUserServiceImpl.class 9KB
Reflections.class 9KB
SysMenu.class 9KB
Order.class 9KB
SysOrg.class 8KB
CarParkManage.class 8KB
CarManageServiceImpl.class 8KB
DynamicQueryImpl.class 8KB
SysRoleServiceImpl.class 8KB
SysLog.class 7KB
CarParkingRecord.class 7KB
SysRole.class 7KB
ApiController.class 7KB
OrderServiceImpl.class 7KB
SysInterface.class 6KB
SysMenuServiceImpl.class 6KB
DistinguishController.class 6KB
CarParkingRecordServiceImpl.class 6KB
SysInterfaceServiceImpl.class 6KB
InterfaceController.class 6KB
ShiroConfig.class 5KB
SysConfig.class 5KB
SysOrgServiceImpl.class 5KB
AppPayConfig.class 5KB
SysConfigServiceImpl.class 5KB
ParkManageServiceImpl.class 5KB
LoginController.class 5KB
SysLandingRecords.class 4KB
BaiDuUtils.class 4KB
CarManageController.class 4KB
ParkManageController.class 4KB
CommonUtils.class 4KB
MqttSenderConfig.class 3KB
PageBean.class 3KB
IndexController.class 3KB
UserRealm.class 3KB
RrExceptionHandler.class 3KB
SysRoleMenu.class 3KB
SysUserRole.class 3KB
MenuController.class 3KB
SysRoleOrg.class 3KB
Result.class 3KB
SysLogServiceImpl.class 3KB
OrderController.class 3KB
SslUtils.class 2KB
MemberController.class 2KB
BaiDuProperties.class 2KB
RoleController.class 2KB
CostUtils.class 2KB
UserController.class 2KB
PayConfigController.class 2KB
SpringUtils.class 2KB
GuavaCacheUtil.class 2KB
IPUtils.class 2KB
DateUtils.class 2KB
CarParkingRecordController.class 2KB
DynamicQuery.class 2KB
SystemConstant.class 2KB
ExcelDataType.class 2KB
PayConfigServiceImpl.class 2KB
Application.class 2KB
ConfigController.class 2KB
OrgController.class 2KB
BigDecimalSerialize.class 2KB
ShiroUtils.class 2KB
SystemConstant$StatusType.class 2KB
MD5Utils.class 2KB
FileConfig.class 1KB
SystemConstant$MenuType.class 1KB
SystemConstant$MacroType.class 1KB
RrException.class 1KB
OrderUtils.class 1KB
SslUtils$miTM.class 1KB
LogController.class 998B
SysUserService.class 759B
GuavaCacheUtil$1.class 681B
CarManageService.class 650B
AbstractController.class 623B
SysMenuService.class 558B
MsgConstant.class 548B
SysInterfaceRepository.class 545B
PayConfigRepository.class 543B
MqttGateway.class 481B
SysLandingRecordsRepository.class 475B
ParkManageService.class 473B
CarParkingRecordRepository.class 472B
ParkManageRepository.class 457B
SysUserRoleRepository.class 457B
SysRoleMenuRepository.class 457B
SysRoleOrgRepository.class 454B
CarManageRepository.class 451B
SysConfigRepository.class 451B
OrderService.class 450B
OrderRepository.class 447B
SysMenuRepository.class 445B
SysUserRepository.class 445B
共 1092 条
- 1
- 2
- 3
- 4
- 5
- 6
- 11
杨校
- 粉丝: 3016
- 资源: 34
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
前往页