作者:乔山办公网日期:
返回目录:excel表格制作
把数据写入到excel模板中,然后把excel下载下来
单击“导出excel”选项,然后选择好储存位置,关闭表格,找到相应的储存位置即可。
要不给你一个可以直接调用的方法吧,你也可以对比修改
/**
* 下载文件
*
* @param request
* @param response
* @param storeName 被下载文件路径
* @param contentType 推荐e799bee5baa6e59b9ee7ad94334:application/octet-stream
* @param realName 下载时显示的文件名称
* @throws Exception
*/
public static void download(HttpServletRequest request, HttpServletResponse response, String storeName, String contentType, String realName)
throws Exception {
request.setCharacterEncoding("UTF-8");
BufferedInputStream bis = null;
BufferedOutputStream bos = null;
try {
String downLoadPath = storeName;
long fileLength = new File(downLoadPath).length();
response.setContentType(contentType);
response.setHeader("Content-disposition", "attachment; filename=" + new String(realName.getBytes("utf-8"), "ISO8859-1"));
response.setHeader("Content-Length", String.valueOf(fileLength));
bis = new BufferedInputStream(new FileInputStream(downLoadPath));
bos = new BufferedOutputStream(response.getOutputStream());
byte[] buff = new byte[2048];
int bytesRead;
while (-1 != (bytesRead = bis.read(buff, 0, buff.length))) {
bos.write(buff, 0, bytesRead);
}
} catch (Exception e) {
e.printStackTrace();
throw e;
} finally {
if (bis != null)
bis.close();
if (bos != null)
bos.close();
}
}
我
细细品味我们的日子,就像一杯西湖龙井,栖凤树上,变成无魂鸟,失去了记忆,