1. 完成用户导出的功能

2. 完成前后端的导出的封装
This commit is contained in:
YunaiV
2021-01-14 01:18:56 +08:00
parent 02ff516f0f
commit f942b34d02
16 changed files with 246 additions and 131 deletions

View File

@ -54,7 +54,7 @@ public class DictConvert implements Converter<Object> {
return null;
}
// 生成 Excel 小表格
return new CellData<>(dictData.getValue());
return new CellData<>(dictData.getLabel());
}
private static DictTypeEnum getType(ExcelContentProperty contentProperty) {

View File

@ -0,0 +1,27 @@
package cn.iocoder.dashboard.framework.excel.core.util;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URLEncoder;
import java.util.List;
/**
* Excel 工具类
*/
public class ExcelUtils {
public static void write(HttpServletResponse response, String filename, String sheetName,
Class<?> head, List<?> data) throws IOException {
// 设置 header 和 contentType
response.addHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(filename, "UTF-8"));
response.setContentType("application/vnd.ms-excel;charset=UTF-8");
// 输出 Excel
EasyExcel.write(response.getOutputStream(), head)
.registerWriteHandler(new LongestMatchColumnWidthStyleStrategy()) // 基于 column 长度,自动适配。最大 255 宽度
.sheet(sheetName).doWrite(data);
}
}