• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
紫色幽灵
软件开发备忘录
博客园    首页    新随笔    联系   管理    订阅  订阅

用java在IE中打开Excel

用java在IE中打开Excel

public class TestOpenExcel extends HttpServlet {  

  private static final String url = "D:/test.xls";  
  protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {    

/**    
* setContentType设置MIME类型,Acrobat  
* PDF文件为"application/pdf",WORD文件为:"application/msword",    
* EXCEL文件为:"application/vnd.ms-excel"。  
*/  
response.setContentType("application/vnd.ms-excel");  

/**    
* setHeader设置打开方式,具体为:inline为在浏览器中打开,attachment单独打开。  
*/  
response.setHeader("Content-disposition", "inline;filename=\"" + "test.xls"+ "\";");  

  ServletOutputStream sos = response.getOutputStream();  

  FileInputStream fis = new FileInputStream(url);      

  BufferedOutputStream bos = new BufferedOutputStream(sos);  
  byte[] bytes = new byte[8192];    

  bos.write(bytes, 0, fis.read(bytes));   fis.close();  

sos.close();  
bos.close();      

}    

  protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {   
    doGet(request, response);  

}    

}



posted @ 2008-01-09 12:28  紫色幽灵  阅读(1705)  评论(2)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3