试试HttpEntity entity = response.getEntity();
数据编码异常,尝试用UTF-8
二进制流 需要给出相应编码, 在本地重新生成相应文件就行了
Action层:
public String service(HttpServletRequest request, HttpServletResponse response) {
try {
HSSFWorkbook wb =exportAllModuleExcel(参数);
// excel 文件的 MIME 类型
response.setContentType("application/msexcel");
// attachment -因为不希望在浏览器中直接打开它,
// 可以通过设置default file name来确定保存文当时的建议名称。
response.setHeader("Content-disposition", "attachment; filename=assessResult.xls");
ServletOutputStream os = response.getOutputStream();
wb.write(os);
os.flush();
os.close();
// 返回到列表页面
return null;
} catch (Exception e) {
generalError(request, e);
e.printStackTrace();
return null;
}
}
}
util工具:
public HSSFWorkbook exportAllModuleExcel(参数) {
HSSFWorkbook wb = new HSSFWorkbook();
ExcelGenerator generator = new ExcelGenerator();
try {
HSSFSheet sheet = wb.createSheet(pss.get(0).getUnitName());
sheet.setDefaultColumnWidth((short) 14);
// 数据格样式
HSSFCellStyle dataCellStyle = createDataCellStyle(wb);
// 标题格样式
@SuppressWarnings("unused")
HSSFCellStyle topDataCellStyle = createTopDataCellStyle(wb);
// 大标题样式
@SuppressWarnings("unused")
HSSFCellStyle titleCellStyle = createTitleCellStyle(wb);
// 创建第一行
HSSFRow row1 = sheet.createRow((short)0);
// 创建第一列
HSSFCell cell1 = row1.createCell((short)0);
} catch (Exception e1) {
e1.printStackTrace();
}
return wb;
}
具体的 分享一篇博客 慢慢研究;
希望能帮到你http://blog.csdn.net/lhooouuu/article/details/6393309