mirror of
https://github.com/continew-org/continew-starter.git
synced 2025-09-14 14:58:39 +08:00
style: 优化代码格式
This commit is contained in:
@@ -28,7 +28,7 @@ import com.alibaba.excel.metadata.property.ExcelContentProperty;
|
||||
/**
|
||||
* Easy Excel 大数值转换器
|
||||
* <p>
|
||||
* Excel 中对长度超过 15 位的数值输入是有限制的,从 16 位开始无论录入什么数字均会变为 0,因此输入时只能以文本的形式进行录入
|
||||
* Excel 中对长度超过 15 位的数值输入是有限制的,从 16 位开始无论录入什么数字均会变为 0,因此输入时只能以文本的形式进行录入
|
||||
* </p>
|
||||
*
|
||||
* @author Charles7c
|
||||
@@ -56,7 +56,7 @@ public class ExcelBigNumberConverter implements Converter<Long> {
|
||||
*/
|
||||
@Override
|
||||
public Long convertToJavaData(ReadCellData<?> cellData, ExcelContentProperty contentProperty,
|
||||
GlobalConfiguration globalConfiguration) {
|
||||
GlobalConfiguration globalConfiguration) {
|
||||
return Convert.toLong(cellData.getData());
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ public class ExcelBigNumberConverter implements Converter<Long> {
|
||||
*/
|
||||
@Override
|
||||
public WriteCellData<Object> convertToExcelData(Long value, ExcelContentProperty contentProperty,
|
||||
GlobalConfiguration globalConfiguration) {
|
||||
GlobalConfiguration globalConfiguration) {
|
||||
if (null != value) {
|
||||
String str = Long.toString(value);
|
||||
if (str.length() > MAX_LENGTH) {
|
||||
|
@@ -44,14 +44,10 @@ public class ExcelUtils {
|
||||
/**
|
||||
* 导出
|
||||
*
|
||||
* @param list
|
||||
* 导出数据集合
|
||||
* @param fileName
|
||||
* 文件名
|
||||
* @param clazz
|
||||
* 导出数据类型
|
||||
* @param response
|
||||
* 响应对象
|
||||
* @param list 导出数据集合
|
||||
* @param fileName 文件名
|
||||
* @param clazz 导出数据类型
|
||||
* @param response 响应对象
|
||||
*/
|
||||
public static <T> void export(List<T> list, String fileName, Class<T> clazz, HttpServletResponse response) {
|
||||
export(list, fileName, "Sheet1", clazz, response);
|
||||
@@ -60,30 +56,25 @@ public class ExcelUtils {
|
||||
/**
|
||||
* 导出
|
||||
*
|
||||
* @param list
|
||||
* 导出数据集合
|
||||
* @param fileName
|
||||
* 文件名
|
||||
* @param sheetName
|
||||
* 工作表名称
|
||||
* @param clazz
|
||||
* 导出数据类型
|
||||
* @param response
|
||||
* 响应对象
|
||||
* @param list 导出数据集合
|
||||
* @param fileName 文件名
|
||||
* @param sheetName 工作表名称
|
||||
* @param clazz 导出数据类型
|
||||
* @param response 响应对象
|
||||
*/
|
||||
public static <T> void export(List<T> list, String fileName, String sheetName, Class<T> clazz,
|
||||
HttpServletResponse response) {
|
||||
HttpServletResponse response) {
|
||||
try {
|
||||
fileName =
|
||||
String.format("%s_%s.xlsx", fileName, DateUtil.format(new Date(), DatePattern.PURE_DATETIME_PATTERN));
|
||||
String.format("%s_%s.xlsx", fileName, DateUtil.format(new Date(), DatePattern.PURE_DATETIME_PATTERN));
|
||||
fileName = URLUtil.encode(fileName);
|
||||
response.setHeader("Content-disposition", "attachment;filename=" + fileName);
|
||||
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8");
|
||||
EasyExcel.write(response.getOutputStream(), clazz).autoCloseStream(false)
|
||||
// 自动适配宽度
|
||||
.registerWriteHandler(new LongestMatchColumnWidthStyleStrategy())
|
||||
// 自动转换大数值
|
||||
.registerConverter(new ExcelBigNumberConverter()).sheet(sheetName).doWrite(list);
|
||||
// 自动适配宽度
|
||||
.registerWriteHandler(new LongestMatchColumnWidthStyleStrategy())
|
||||
// 自动转换大数值
|
||||
.registerConverter(new ExcelBigNumberConverter()).sheet(sheetName).doWrite(list);
|
||||
} catch (Exception e) {
|
||||
log.error("Export excel occurred an error: {}. fileName: {}.", e.getMessage(), fileName, e);
|
||||
throw new BaseException("导出 Excel 出现错误");
|
||||
|
Reference in New Issue
Block a user