Excel下载模板配合的工具类
来源:互联网 发布:中国纺织品出口数据图 编辑:程序博客网 时间:2024/05/01 18:55
Excel下载模板配合的工具类
public class ExportUtil {
/**
* 导出文件
*
* @param response
* @param file
* 导出文件
* @param name
* @param contentType
* @throws IOException
*/
public static void download(HttpServletResponse response, File file,
String name, String contentType) throws IOException {
String fileName = StringUtils.isBlank(name) ? file.getName() : name;
download(response, new FileInputStream(file), fileName, contentType);
}
/**
* 下载数据/文件
*
* @param response
* HTTP输出
* @param inputStream
* 文件流
* @param fileName
* 文件名
* @param contentType
* ContentType in HTTP Header
* @throws IOException
* IO异常
*/
public static void download(HttpServletResponse response,
InputStream inputStream, String fileName, String contentType)
throws IOException {
response.setContentType(StringUtils.isEmpty(contentType) ? "application/octet-stream"
: contentType);
/**
* 导出文件
*
* @param response
* @param file
* 导出文件
* @param name
* @param contentType
* @throws IOException
*/
public static void download(HttpServletResponse response, File file,
String name, String contentType) throws IOException {
String fileName = StringUtils.isBlank(name) ? file.getName() : name;
download(response, new FileInputStream(file), fileName, contentType);
}
/**
* 下载数据/文件
*
* @param response
* HTTP输出
* @param inputStream
* 文件流
* @param fileName
* 文件名
* @param contentType
* ContentType in HTTP Header
* @throws IOException
* IO异常
*/
public static void download(HttpServletResponse response,
InputStream inputStream, String fileName, String contentType)
throws IOException {
response.setContentType(StringUtils.isEmpty(contentType) ? "application/octet-stream"
: contentType);
/*这里的StringUtil是一个工具类用来判断空字符的
* 字符串非空验证
* @param str 验证字符串
* @return 验证结果
public static boolean isEmpty(String str){
if(null==str || str.equals("")){
return true;
}
return false;
}
*/
response.setHeader("Content-Disposition", "attachment;filename="
+ new String(fileName.getBytes("gbk"), "ISO-8859-1"));
response.setStatus(HttpServletResponse.SC_OK);
BufferedInputStream reader = null;
try {
reader = new BufferedInputStream(inputStream);
IOUtils.copy(reader, response.getOutputStream());
} finally {
if (reader != null) {
reader.close();
}
if (inputStream != null) {
inputStream.close();
}
}
}
}
* 字符串非空验证
* @param str 验证字符串
* @return 验证结果
public static boolean isEmpty(String str){
if(null==str || str.equals("")){
return true;
}
return false;
}
*/
response.setHeader("Content-Disposition", "attachment;filename="
+ new String(fileName.getBytes("gbk"), "ISO-8859-1"));
response.setStatus(HttpServletResponse.SC_OK);
BufferedInputStream reader = null;
try {
reader = new BufferedInputStream(inputStream);
IOUtils.copy(reader, response.getOutputStream());
} finally {
if (reader != null) {
reader.close();
}
if (inputStream != null) {
inputStream.close();
}
}
}
}
阅读全文
0 0
- Excel下载模板配合的工具类
- 简单的下载excel模板
- velocity导出Word,excel模板的工具类
- EXCEL模板的上传个下载
- 迅雷批量下载。。。通配符,配合excel
- java生成excel和下载导出文件的工具类
- Util工具类 提供下载转码中文名称的excel
- java实现excel下载和上传的工具类
- 下载excel模板
- excel 下载模板
- 动态下载Excel模板
- 下载excel模板
- 下载excel模板
- EXCEL下载模板
- excel 下载模板
- Java 下载 Excel模板
- excel模板文件下载
- Java里的下载Excel模板上传Excel文件
- 奇异值分解SVD--简单理论
- 异常处理:ASM ClassReader failed to parse class file的分析与解决
- mysql并行复制降低主从同步延时的思路与启示
- apache与tomcat 连接安装问题
- (二) vue 传值
- Excel下载模板配合的工具类
- WPF 窗体样式重写 界面优美-下载
- springcloud学习之旅(一)服务的注册于发现
- CentOS 7防火墙设置开放80端口
- 安装centos7并配置上网和安装ftp
- 互联网公司为啥不使用mysql分区表?(一分钟系列)
- arcgisserver manage 无法启动问题
- MySQL高可用方案选型参考
- spring定时器详解