2024年5月11日发(作者:sql2000下载免费版)
java下载excel文件
原代码剪切图片:
修改后剪切图片:
源码:
public void downloadTaskModel()throws Exception{
HttpServletResponse
text().getResponse();
response =
HttpServletRequest request = text().getRequest();
String path = lPath("/");
path = new String(es("iso-8859-1"),"GBK");
String matches = "[A-Za-z]:[^:?"><*]*";
if(!s(matches)){
throw new Exception("文件路径存在非法字符!");
}
path = eAll("", "/");
File file = new File(path+"/templateFile/");
if(!()||!()||ctory()){
throw new Exception("下载的文件路径或文件不存在!");
}
//由于限制了导入模板的类型,所以在导出模板时必须限制。
if(!e().matches(".*.(?i)(xls)$")){
throw new Exception("当前模板类型有误,只能导出“.xls”格式的excel模板!");
}
tentType("application/x-msdownload");
tentLength((int)());
String taskNme = eStr(new Date(), "yyyyMMddHHmmss");
der("Content-Disposition",
"attachment;filename="+("模板"+taskNme+".xls","UTF-8"));
FileInputStream fis = new FileInputStream(file);
BufferedInputStream buff = new BufferedInputStream(fis);
byte b[] = new byte[1024];
long k = 0 ;
OutputStream myout = putStream();
while(k<()){
int j = (b,0,1024);
k += j ;
(b,0,j);
}
();
();
}
发布者:admin,转转请注明出处:http://www.yc00.com/xitong/1715382285a2609659.html
评论列表(0条)