Ryla
asked on
Using Interop.Excel to generate excel file and export to excel
I am using the interop.excel to generate an excel file that I will be exporting to excel. It works fine if I save it to my C drive. But I want to be able to export to excel and give the user a file download prompt with the opens save, open or cancel. If I use
Response.AddHeader("conten t-disposit ion","atta chment;fil ename=Hell o.xls")
Response.ContentType="appl ication/vn d.ms-excel "
Response.Write(MyWorkBook)
my opened window hangs. Any suggestions?
Response.AddHeader("conten
Response.ContentType="appl
Response.Write(MyWorkBook)
my opened window hangs. Any suggestions?
pl try Response.BinaryWrite()
try using a stringwriter:
Dim sw As New StringWriter()
httpContext.Current.Response.ClearContent()
HttpContext.Current.Response.AddHeader("content-disposition", "attachment; filename=" & filename)
HttpContext.Current.Response.ContentType = "application/vnd.xls"
HttpContext.Current.Response.Charset = ""
HttpContext.Current.Response.Write(sw.ToString())
HttpContext.Current.Response.End()
sw.Dispose()
ASKER
NeilFleming1, Do you think this will solve the Excel 2007 issue of the warning "The file you are trying to open, 'filename.xls', is in a different format than specified by the file extension. Verify that the file is not corrupted and is from a trusted source before opening the file. Do you want to open the file now?"
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
PS Microsoft's own advice is to ignore the warning -- the file opens fine in any case.
Try some other method such as Response.WriteFile or Response.OutputStream.Writ e
http://forums.asp.net/t/1042980.aspx
http://support.microsoft.com/kb/306654
http://dotnetslackers.com/Community/blogs/haissam/archive/2007/04/03/Downloading-Files-C_2300_.aspx
http://forums.asp.net/t/1042980.aspx
http://support.microsoft.com/kb/306654
http://dotnetslackers.com/Community/blogs/haissam/archive/2007/04/03/Downloading-Files-C_2300_.aspx