史上最全的excel读写技术分享_烟花散尽13141的博客-CSDN博客_aftercelldispose
EasyPoi实现excel文件导入导出_crysw的博客-CSDN博客_easypoi excel导入
public class OfficialExcelUtil {
public static void exportExcel(List> list, Class> pojoClass, String fileName, boolean isCreateHeader, HttpServletResponse response) {
ExportParams exportParams = new ExportParams();
exportParams.setCreateHeadRows(isCreateHeader);
Workbook workbook = ExcelExportUtil.exportExcel(exportParams, pojoClass, list);
if (workbook != null) ;
try {
response.setCharacterEncoding("UTF-8");
response.setHeader("content-Type", "application/vnd.ms-excel");
response.setHeader("Content-Disposition",
"attachment;filename=" + URLEncoder.encode(fileName, "UTF-8"));
workbook.write(response.getOutputStream());
} catch (IOException e) {
try {
throw new Exception(e.getMessage());
} catch (Exception e1) {
e1.printStackTrace();
}
}
}
}
//实体字段
private byte[] oilCostRecord;
//下载后下来后转成字节
Result result = systemMinioProvider.downloadBase64(record.getRecord());
String split = result.getData().toString().split("base64,")[1];
byte[] decode = Base64.getDecoder().decode(split);
ExcelVo.setRecord(decode);
//调用导出
Workbook workbook = ExcelExportUtil.exportExcel(exportParams, pojoClass, list);
EasyExcel导入存在合并单元格的Excel_easyexcel导入合并单元格_我可能在扯淡的博客-CSDN博客
EasyExcel模板导出(行和列自动合并)_easyexcel 模板导出_Lzfnemo2009的博客-CSDN博客(牛逼)
EasyExcel导出合并单元格_easyexcel合并单元格_是一个菜鸟程序员啊的博客-CSDN博客
https://www.jb51.net/article/258822.htm EasyExcel工具读取Excel空数据行问题的解决办法
EasyExcel实现Excel文件导入导出_crysw的博客-CSDN博客_easyexcel
@Slf4j
@Component
public class ExcelExportHandler {
/**
* 下载Excel格式的数据
*
* @param response response
* @param fileName 文件名(支持中文)
* @param data 待下载的数据
* @param map key 为对象中的字段名 value 为表头展示的文字
* @param 数据泛型
*/
public static void export(HttpServletResponse response, String fileName,
List data, LinkedHashMap map) throws IOException {
ExcelWriter writer = ExcelUtil.getWriter();
// 数据为空,打印表头
if (CollectionUtil.isEmpty(data)){
writer.writeHeadRow(map.values());
}
for(String str : map.keySet()){
writer.addHeaderAlias(str,map.get(str));
}
writer.setColumnWidth(-1, 30);
writer.setRowHeight(-1, 20);
writer.write(data,true);
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset:utf-8");
fileName= URLEncoder.encode(fileName,"UTF-8");
response.setHeader("Content-Disposition","attachment;filename="+fileName+".xlsx");
ServletOutputStream outputStream= response.getOutputStream();
writer.flush(outputStream,true);
outputStream.close();
writer.close();
}
}
(8条消息) Springboot导出EXCEl方法(若依实例)_星光榴莲鸡的博客-CSDN博客_springboot导出excel表格
问题1:
使用fileName = URLEncoder.encode(fileName, "UTF-8");偶尔不生效时,使用下面方法解决中文乱码问题。
JAVA输出EXCEL文件名中文乱码解决
response.setCharacterEncoding(“UTF-8”);
String filename = new String( “明细记录”.getBytes(“utf-8” ), “ISO8859-1” );
response.setHeader(“Content-disposition”, “attachment; filename=”+filename+".xls");// 设定输出文件头
response.setContentType(“application/msexcel”);// 定义输出类型
————————————————
版权声明:本文为CSDN博主「weixin_43972670」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/weixin_43972670/article/details/120525642
问题2:
说法1:
注意导出的controller中,不能有返回值,改为void,防止IO流冲突。
说法2:
controller添加返回值json后报错。
结论:下载文件时controller方法只能返回null或者void。
原因:因为response已经输出了,无论你返回不返回都没啥用了
解决方法:导出的接口调用返回null
@GetMapping("/exportIMO/year")
public ResponseResult exportImo(HttpServletResponse response, @RequestParam Integer year){
Date firstDate = DateUtil.getYearFirst(year);
Date lastDate = DateUtil.getAfterDay(DateUtil.getYearLast(year));
if (!iImoVoyageService.isBeginPeriodOil(firstDate, lastDate)){
return ResponseResult.fail("查询的开始时间和结束时间的期初存油均不能为空");
}else {
try {
iImoVoyageService.exportIMOVoyageData(response,firstDate,lastDate,"1");
return null;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
(8条消息) Java实现根据excel模板导出数据(适合导出结构复杂的excel)_名字看着办的博客-CSDN博客_java根据模板导出excel
使用EasyExcel实现excel导出,支持百万大数据量导出-----超简单_easyexcel导出大量数据_MCP~的博客-CSDN博客