发表于: 2017-04-11 21:28:11

1 1213


今天完成的事情:文件下载格式转换
明天计划的事情:完成项目任务 
遇到的问题:文件一开始是zip格式下载的,需求变动,要改为xls格式。我上去把后缀改为.xls,可以下载但是打开文件是乱码,懵了。后来问了下带我的老师,被骂了,说是这样改后缀,文件本质还没变。我控制住了难过的情绪,想了一会儿,直接把压缩功能注释掉,改了下下载路径,问题解决

public void export() throws Exception{

HttpServletRequest request = ServletActionContext.getRequest();

String exportData = request.getParameter("exportData");

String uuid = StringUtility.getUUID();

JSONObject jSONObject = JSONObject.fromObject(exportData);

JSONObject excelObject = jSONObject.getJSONObject("excelData");

String fileName = (String) excelObject.get("name");

if(fileName ==null || fileName ==""){

throw new Exception("统计结果为空,不可导出!");

}

//临时文件路径初始化

String tmpDirName = this.getTmpDirName(uuid);

//生成EXCEL

this.createExcelFile(excelObject, tmpDirName);

String filePath = this.createExcelFile(excelObject, tmpDirName).toString();

// download(this.createExcelFile(excelObject, tmpDirName));

JSONArray jSONArray = jSONObject.getJSONArray("chartsData");

List<MorphDynaBean> i =  (List<MorphDynaBean>) JSONArray.toCollection(jSONArray);

//生成图表

for(MorphDynaBean bean : i){

this.createChart(bean, tmpDirName);

}

//需求改变,要下载xls格式,压缩功能先不用

// String zip = tmpDirName.substring(0,tmpDirName.length()-1) + ".zip";

// ZipCompressorByAnt zca = new ZipCompressorByAnt(zip);   //apache ant方式压缩

// zca.compress(tmpDirName);

this.sendJSONWeb("{success:true,uuid:'" + uuid + "'}");

}


String downPath = tmpDirName.substring(0,tmpDirName.length()-1) + "\\统计数据.xls"; 


收获: 有文件路径就可以创建文件,zip下载一半用于多个文件打包下载,压缩方法有apache的ant,递归也可以压缩。


返回列表 返回列表
评论

    分享到