81,092
社区成员
发帖
与我相关
我的任务
分享
XWPFDocument doc = null;
// ... 经过一系列逻辑,写入操作之后非空
// ...
// 避免空指针
if (null != doc) {
// 拼接文件名,下载时显示的名字
String fileName = "MyInfo.docx";
// response的一些头设置
resp.setHeader("Content-Disposition", "attachment;filename=" + fileName);
resp.setContentType("application/x-download;charset=utf-8");
resp.setCharacterEncoding("utf-8");
// 最后文件流写入到页面响应的输出流中
doc.write(resp.getOutputStream());
resp.flushBuffer();
}
excel应该类似,试试吧!