日期:2014-05-17  浏览次数:20649 次

求教,导出生成Excel 是弹出下载框。

FileOutputStream fileOut = new FileOutputStream("C:/Users/Administrator/Desktop/测试ONG.xls");            
wb.write(fileOut);            
fileOut.close();

我现在是直接把文件生成在桌面上的, 我想要先弹出下载框,然后自己选择保存路径,请问怎么弄,请各位教教小弟,能有代码最好了,谢谢。
Excel Java File 导出 下载

------解决方案--------------------
public InputStream getInputStream() throws Exception {
Annex annex=annexService.find(Annex.class, id);
File file = new File(getFileBasePath() + annex.getUrl());
File file2=new File(getFileBasePath() + File.separator+"download"+File.separator+DecoderUtil.UtfDecoder(annex.getName()));
file2.getParentFile().mkdir();
FileUtil.copyFile(file, file2);
try {
this.setFileName(new String(file2.getName().getBytes(), "ISO8859-1"));
tempStream = new java.io.FileInputStream(file2);//从系统磁盘文件读取数据
bytes = new byte[tempStream.available()];
if(tempStream != null) {
tempStream.read(bytes);
}
tempStream.close();
return new ByteArrayInputStream(bytes);
}  catch(Exception e) {
return null;
}finally{
FileUtil.deleteFile(file2.toString());
}
}

这个是下载的action,我写的一个简单的东西
------解决方案--------------------
这个导出成功了也是一样的,直接就下载了
/**
 * wangjiafeng
 * TODO 导出自行车电动车信息Excel
 * @method educeExcel
 * @return
 * @throws Exception
 * 2013 上午10:20:25
 */
public String educeEleCarExcel() throws Exception{
Member member=getMember();
if(member != null ){
Date date=new Date(System.currentTimeMillis());
String test=DateUtil.parseDateToString(date, "yyyy-MM-ddHH:mm:ss").replace("-", "").replace(":", "").trim();
String path = request.getSession().getServletContext().getRealPath("/") + "ElectCarExcel"+test+".xls";