如题 源码如下,跪求高手指教 public ActionForward exportCard() {
String title = batch.getId() + "_批次卡密信息";
String name = "cp";
String webPath = ParamInstance.getParam("excel_path");
if(type == 2) {
title = batch.getId() + "_红包信息";
name = "exp";
}
batch = SysEnv.getCardBatchService().getBatchById(batch.getId());
File file = new File(webPath);
String[] fileNames = file.list();
String[] webPaths = null;
List<String> strs = new ArrayList<String>();
boolean isMake = false;
int fileNum = 0;
CardExcel cardexcel = new CardExcel();
for (int i = 0; i < fileNames.length; i++) {
if(fileNames[i].indexOf(batch.getId() + "_" + name + "_") != -1) {
strs.add(webPath + "/" + fileNames[i]);
if(cardexcel.excelIsNull(webPath + "/" + fileNames[i])) {
break;
}
fileNum ++ ;
}
}
int temp = batch.getTotalCount() / Integer.parseInt(ParamInstance.getParam("export_num"));
if(batch.getTotalCount() <= Integer.parseInt(ParamInstance.getParam("export_num"))) {
temp = temp + 1;
} else {
if(batch.getTotalCount() % Integer.parseInt(ParamInstance.getParam("export_num")) != 0) {
temp = temp + 1;
}
}
if(temp == fileNum) {
isMake = true;
}
if(!isMake) {
strs.clear();
new CardExcel(title, batch, webPath, type);
fileNames = file.list();
for (int i = 0; i < fileNames.length; i++) {
if(fileNames[i].indexOf(batch.getId() + "_" + name + "_") != -1) {
strs.add(webPath + "/" + fileNames[i]);
}
}
}
if(strs.size() != 0) {
webPaths = FileUtils.listToArray(strs);
}
try {
title = URLEncoder.encode(title, "utf-8");//header头要进过编码
response.reset();//清空输出流
response.setContentType("application/zip;charset=UTF-8");
// response.setContentType("application/vnd.ms-excel;charset=UTF-8");//定义输出类型
response.setHeader("Content-disposition", "attachment;filename="+title+".zip");//设定输出文件头
FileUtils.createZip(response.getOutputStream(), webPaths);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
String title = batch.getId() + "_批次卡密信息";
String name = "cp";
String webPath = ParamInstance.getParam("excel_path");
if(type == 2) {
title = batch.getId() + "_红包信息";
name = "exp";
}
batch = SysEnv.getCardBatchService().getBatchById(batch.getId());
File file = new File(webPath);
String[] fileNames = file.list();
String[] webPaths = null;
List<String> strs = new ArrayList<String>();
boolean isMake = false;
int fileNum = 0;
CardExcel cardexcel = new CardExcel();
for (int i = 0; i < fileNames.length; i++) {
if(fileNames[i].indexOf(batch.getId() + "_" + name + "_") != -1) {
strs.add(webPath + "/" + fileNames[i]);
if(cardexcel.excelIsNull(webPath + "/" + fileNames[i])) {
break;
}
fileNum ++ ;
}
}
int temp = batch.getTotalCount() / Integer.parseInt(ParamInstance.getParam("export_num"));
if(batch.getTotalCount() <= Integer.parseInt(ParamInstance.getParam("export_num"))) {
temp = temp + 1;
} else {
if(batch.getTotalCount() % Integer.parseInt(ParamInstance.getParam("export_num")) != 0) {
temp = temp + 1;
}
}
if(temp == fileNum) {
isMake = true;
}
if(!isMake) {
strs.clear();
new CardExcel(title, batch, webPath, type);
fileNames = file.list();
for (int i = 0; i < fileNames.length; i++) {
if(fileNames[i].indexOf(batch.getId() + "_" + name + "_") != -1) {
strs.add(webPath + "/" + fileNames[i]);
}
}
}
if(strs.size() != 0) {
webPaths = FileUtils.listToArray(strs);
}
try {
title = URLEncoder.encode(title, "utf-8");//header头要进过编码
response.reset();//清空输出流
response.setContentType("application/zip;charset=UTF-8");
// response.setContentType("application/vnd.ms-excel;charset=UTF-8");//定义输出类型
response.setHeader("Content-disposition", "attachment;filename="+title+".zip");//设定输出文件头
FileUtils.createZip(response.getOutputStream(), webPaths);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货