🚩 新增操作excel时快速获取Content-Type的方法

This commit is contained in:
NanCheung 2021-06-08 11:14:51 +08:00
parent 0f5133013d
commit 4ee9c2cb08
2 changed files with 60 additions and 37 deletions

View File

@ -25,6 +25,16 @@ import java.io.InputStream;
*/
public class ExcelUtil {
/**
* xlx的ContentType
*/
public static final String XLS_CONTENT_TYPE = "application/vnd.ms-excel;charset=utf-8";
/**
* xlsx的ContentType
*/
public static final String XLSX_CONTENT_TYPE = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8";
// ------------------------------------------------------------------------------------ Read by Sax start
/**
* 通过Sax方式读取Excel同时支持03和07格式

View File

@ -382,6 +382,19 @@ public class ExcelWriter extends ExcelBase<ExcelWriter> {
return StrUtil.format("attachment; filename=\"{}\"; filename*={}''{}", fileName, charset.name(), fileName);
}
/**
* 获取Content-Type头对应的值可以通过调用以下方法快速设置下载Excel的头信息
*
* <pre>
* response.setContentType(excelWriter.getContentType());
* </pre>
*
* @return Content-Type值
*/
public String getContentType() {
return isXlsx() ? ExcelUtil.XLSX_CONTENT_TYPE : ExcelUtil.XLS_CONTENT_TYPE;
}
/**
* 设置当前所在行
*