Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 29th, 2012  |  syntax: None  |  size: 0.75 KB  |  hits: 15  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. How to open excel 2007/2010 on browser by using .ashx?
  2. <a href="test.htm" target="_blank">Export</a>
  3.        
  4. <iframe src="handler1.ashx" style="height: 421px; width: 800px" ></iframe>
  5.        
  6. void ProcessRequest(HttpContext context)
  7.     {
  8.  
  9.         string filePath = "E:/test.xlsx";
  10.         string filename = Path.GetFileName(filePath);
  11.         context.Response.Clear();
  12.         context.Response.AddHeader("Content-Disposition", "inline;filename=test.xlsx");
  13.         context.Response.Charset = "";
  14.         context.Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
  15.         context.Response.WriteFile(filePath);
  16.         context.Response.Flush();
  17.         context.Response.End();
  18.     }
  19.        
  20. context.Response.Write(YourExcelData);