Pre Merge pull request !255 from 云飞扬/N/A

This commit is contained in:
云飞扬 2022-09-24 18:12:03 +00:00 committed by Gitee
commit 835bad8bf5
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 28 additions and 19 deletions

View File

@ -2,10 +2,12 @@ package com.ruoyi.common.core.utils.poi;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.math.BigDecimal;
import java.net.URLEncoder;
import java.text.DecimalFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
@ -255,7 +257,7 @@ public class ExcelUtil<T>
/**
* 对excel表单默认第一个索引名转换成list
*
*
* @param is 输入流
* @return 转换后集合
*/
@ -266,7 +268,7 @@ public class ExcelUtil<T>
/**
* 对excel表单默认第一个索引名转换成list
*
*
* @param is 输入流
* @param titleNum 标题占用行数
* @return 转换后集合
@ -278,7 +280,7 @@ public class ExcelUtil<T>
/**
* 对excel表单指定表格索引名转换成list
*
*
* @param sheetName 表格索引名
* @param titleNum 标题占用行数
* @param is 输入流
@ -455,6 +457,11 @@ public class ExcelUtil<T>
public void exportExcel(HttpServletResponse response, List<T> list, String sheetName, String title)
{
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
try {
response.addHeader("Content-Disposition", "attachment;FileName=" + URLEncoder.encode(title,"utf-8"));
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
response.setCharacterEncoding("utf-8");
this.init(list, sheetName, title, Type.EXPORT);
exportExcel(response);
@ -488,7 +495,7 @@ public class ExcelUtil<T>
/**
* 对list数据源将其里面的数据导入到excel表单
*
*
* @return 结果
*/
public void exportExcel(HttpServletResponse response)
@ -550,7 +557,7 @@ public class ExcelUtil<T>
/**
* 填充excel数据
*
*
* @param index 序号
* @param row 单元格行
*/
@ -614,7 +621,7 @@ public class ExcelUtil<T>
/**
* 创建表格样式
*
*
* @param wb 工作薄对象
* @return 样式列表
*/
@ -667,7 +674,7 @@ public class ExcelUtil<T>
/**
* 根据Excel注解创建表格头样式
*
*
* @param wb 工作薄对象
* @return 自定义样式列表
*/
@ -681,6 +688,7 @@ public class ExcelUtil<T>
if (!headerStyles.containsKey(key))
{
CellStyle style = wb.createCellStyle();
style = wb.createCellStyle();
style.cloneStyleFrom(styles.get("data"));
style.setAlignment(HorizontalAlignment.CENTER);
style.setVerticalAlignment(VerticalAlignment.CENTER);
@ -700,7 +708,7 @@ public class ExcelUtil<T>
/**
* 根据Excel注解创建表格列样式
*
*
* @param wb 工作薄对象
* @return 自定义样式列表
*/
@ -714,6 +722,7 @@ public class ExcelUtil<T>
if (!styles.containsKey(key))
{
CellStyle style = wb.createCellStyle();
style = wb.createCellStyle();
style.setAlignment(excel.align());
style.setVerticalAlignment(VerticalAlignment.CENTER);
style.setBorderRight(BorderStyle.THIN);
@ -762,7 +771,7 @@ public class ExcelUtil<T>
/**
* 设置单元格信息
*
*
* @param value 单元格值
* @param attr 注解相关
* @param cell 单元格信息
@ -909,7 +918,7 @@ public class ExcelUtil<T>
/**
* 设置 POI XSSFSheet 单元格提示或选择框
*
*
* @param sheet 表单
* @param textlist 下拉框显示的内容
* @param promptContent 提示内容
@ -983,7 +992,7 @@ public class ExcelUtil<T>
/**
* 反向解析值 =0,=1,未知=2
*
*
* @param propertyValue 参数值
* @param converterExp 翻译注解
* @param separator 分隔符
@ -1224,7 +1233,7 @@ public class ExcelUtil<T>
/**
* 创建工作表
*
*
* @param sheetNo sheet数量
* @param index 序号
*/
@ -1241,7 +1250,7 @@ public class ExcelUtil<T>
/**
* 获取单元格值
*
*
* @param row 获取的行
* @param column 获取单元格列号
* @return 单元格值
@ -1301,7 +1310,7 @@ public class ExcelUtil<T>
/**
* 判断是否是空行
*
*
* @param row 判断的行
* @return
*/
@ -1324,7 +1333,7 @@ public class ExcelUtil<T>
/**
* 格式化不同类型的日期对象
*
*
* @param dateFormat 日期格式
* @param val 被格式化的日期对象
* @return 格式化后的日期字符
@ -1390,7 +1399,7 @@ public class ExcelUtil<T>
/**
* 获取对象的子列表方法
*
*
* @param name 名称
* @param pojoClass 类对象
* @return 子列表方法

View File

@ -27,7 +27,7 @@ import com.ruoyi.common.core.web.page.TableDataInfo;
/**
* ${functionName}Controller
*
*
* @author ${author}
* @date ${datetime}
*/
@ -63,12 +63,12 @@ public class ${ClassName}Controller extends BaseController
*/
@RequiresPermissions("${permissionPrefix}:export")
@Log(title = "${functionName}", businessType = BusinessType.EXPORT)
@PostMapping("/export")
@PostMapping(value = "/export", produces = "application/octet-stream")
public void export(HttpServletResponse response, ${ClassName} ${className})
{
List<${ClassName}> list = ${className}Service.select${ClassName}List(${className});
ExcelUtil<${ClassName}> util = new ExcelUtil<${ClassName}>(${ClassName}.class);
util.exportExcel(response, list, "${functionName}数据");
util.exportExcel(response, list, "${functionName}数据", "${functionName}数据");
}
/**