wysiwyg logo How to prevent from IE to open the Excel file, save as instead of open the file.

<%@ CODEPAGE="65001" LANGUAGE="VBScript" %>
<%

	Response.Buffer = True
	Response.ContentType = "application/vnd.ms-excel"  '// define ContentType 
	Response.Charset = "utf-8"			   '// define Charset to utf 8
	
	  '// define file name to save as attachment
	Response.AddHeader "Content-Disposition", "attachment; filename=rep2xls.xls"
	
	  '// create table (grid) and collect record set date
	Response.Write "<table>"
	sql = "SELECT * from orders WHERE MyStatus>0 order by id desc"
	set rs1 = conn.execute(sql)
	while not rs1.eof
		itemQprice = rs1("itemQprice")
		quantity = rs1("quantity")
		prdPrice = rs1("prdPrice")
		
		Response.Write "<tr>" & _
		"<td>" & itemQprice & "</td>" & _
		"<td>" & quantity & "</td>" & _
		"<td>" & prdPrice & "</td>" & _
		"</tr>"		
		rs.movenext
	wend
	  '// close table
	Response.Write "</table>"
	
	  '// Flush the result
	Response.end
%>

live demo
Other MIME type or ContentType




xnet 1998 - 2011