|
|
@@ -34,6 +34,10 @@ public class ExcelWriteUtil {
|
|
|
*/
|
|
|
public static <T> void writeToResponse(HttpServletResponse response, final String fileName, final String excelTitle, final Map<String, String> titleMap, final List<T> list, final Class<T> tClass) {
|
|
|
try {
|
|
|
+ //设置响应头
|
|
|
+ response.setContentType("application/octet-stream");
|
|
|
+ response.setHeader("Content-Disposition", String.format("attachment;filename=%s%s", fileName, ".xls"));
|
|
|
+
|
|
|
@Cleanup ExcelWriter writer = ExcelUtil.getWriter();
|
|
|
//写入标题
|
|
|
writer.merge(titleMap.size() - 1, excelTitle);
|
|
|
@@ -64,9 +68,6 @@ public class ExcelWriteUtil {
|
|
|
}
|
|
|
i++;
|
|
|
}
|
|
|
- //设置响应头
|
|
|
- response.setContentType("application/octet-stream");
|
|
|
- response.setHeader("Content-Disposition", String.format("attachment;filename=%s%s", fileName, ".xls"));
|
|
|
writer.flush(response.getOutputStream(), true);
|
|
|
} catch (Exception e) {
|
|
|
log.error(e.getMessage());
|