Easyexcel导出并下载excel到本地
easyexcel
快速、简洁、解决大文件内存溢出的java处理Excel工具
项目地址:https://gitcode.com/gh_mirrors/ea/easyexcel
免费下载资源
·
后端:
public AjaxResult easyExcelAction(Tj0staff tj0staff)
{
//创建文件
FileOutputStream fileOut;
String reFileName = "static/img";
if (!new File(Global.getProfile() + "/" + reFileName).exists()) {
new File(Global.getProfile() + "/" + reFileName).mkdirs();
}
reFileName = reFileName+"/tj.xlsx";
StringBuilder fileName = new StringBuilder();
fileName.append(Global.getProfile() + "/" + reFileName);
try {
//String dateStr = tools.getStringTodayNoKong();
System.out.println("准备插入的文件名是:" + fileName);
//需要先成一个后缀是。xlsx的文件,格式不对,不能正常打开
File fileFill07 = new File(fileName.toString());
if(!fileFill07.exists()){
fileFill07.createNewFile();
}
String LargFilePath = "large";
String large = LargFilePath+"/fill_v02.xlsx";
StringBuilder fileNameLarg = new StringBuilder();
fileNameLarg.append(Global.getProfile() + "/" + large);
System.out.println("模板路径:"+fileNameLarg.toString());
File template07 = new File(fileNameLarg.toString());
ExcelWriter excelWriter = EasyExcel.write(fileFill07).withTemplate(template07).build();
WriteSheet writeSheet = EasyExcel.writerSheet().build();
List<Tj0staff> tj0staffs = tj0staffService.selectTjAllList(tj0staff);
System.out.println("待导出的数据" + tj0staffs);
excelWriter.fill(tj0staffs, writeSheet);
excelWriter.finish();
} catch (Exception e) {
e.printStackTrace();
logger.error("导出出错:{}", e.getMessage());
return error("导出出错!");
}
return success(Constants.RESOURCE_PREFIX+"/"+reFileName);
}
难点是读取和保存路径,在打包后不能正常,不要放到项目中。
前端
function easyExcel() {
var formatter = $("#formId").serialize();
console.log(formatter)
if ($("#startTime").val() == "") {
$.modal.alertError("请选择开始时间");
return false;
}if ($("#endTime").val() == "") {
$.modal.alertError("请选择结束时间");
return false;
}
$.operate.post(ctx + "tj/0staff/easyExcel", formatter, function (data) {
if (data.code == 0) {
window.open(ctx + 'common/download/resource?resource=' + data.msg);
} else {
$.modal.alertError(data.msg);
}
}, 'json');
/*$.ajax({
type: "post",
dataType: "json",
contentType: "application/json",
url: ctx + "tj/0staff/easyExcel/",
data: formatter,
success: function (data) {
if (data.code == 0) {
window.location.href = ctx + 'common/download/resource?resource=' + data.msg;
} else {
$.modal.alertError(data.msg);
}
}
});*/
/* var aa = httpPost("http://127.0.0.1/tj/0staff/easyExcel", formatter);
alert("------执行结果--------"+aa);*/
}
调用了系统中的组件,而不是用ajax,实现了传递对象参数。
GitHub 加速计划 / ea / easyexcel
16
5
下载
快速、简洁、解决大文件内存溢出的java处理Excel工具
最近提交(Master分支:5 个月前 )
c42183df
Bugfix 5 个月前
efa7dff6 * 重新加回 `commons-io`
5 个月前
更多推荐
已为社区贡献2条内容
所有评论(0)