Dynamically creating .xls file.

G

Guest

Greetings,

I’ve query some data from the table, how can I push it into an excel file and allow user to save it? anyone done this sort of thing before?
 
G

Guest

Select Case (svlType.ToLower)
Case "txt" : svlType = "text/plain"
Case "htm" : svlType = "text/HTML"
Case "html" : svlType = "text/HTML"
Case "pdf" : svlType = "Application/pdf"
Case "gif" : svlType = "image/GIF"
Case "jpg" : svlType = "image/JPEG"
Case "jpeg" : svlType = "image/JPEG"
Case "png" : svlType = "image/png"
Case "doc" : svlType = "Application/msword" ' (for Microsoft Word files)
Case "xls" : svlType = "Application/x-msexcel" '(for Microsoft Excel files)
End Select

HttpContext.Current.Response.ContentType =svlType
HttpContext.Current.Response.write(YourVariable)

YourVariable is the variable which holds data.

In case while saving if you expect the file to be saved in a filename you specify You can use

HttpContext.Current.Response.AppendHeader("Content-disposition", "attachment; filename=" & myFileName)


In the case with FileName, use it as follows:


HttpContext.Current.Response.ContentType =svlType
HttpContext.Current.Response.AppendHeader("Content-disposition", "attachment; filename=" & myFileName)
HttpContext.Current.Response.write(YourVariable)
 
E

Edward

if do like this, can the client application open the file correctly. PDF,
gif, jpeg etc. are all not plain text files, word, excel needless to say.

In my opinion, we should try to use COM+ or some other ways to generate xls
file, and send back to client. in this newsgroup, there are a lot of
threads on this topic.
Select Case (svlType.ToLower)
Case "txt" : svlType = "text/plain"
Case "htm" : svlType = "text/HTML"
Case "html" : svlType = "text/HTML"
Case "pdf" : svlType = "Application/pdf"
Case "gif" : svlType = "image/GIF"
Case "jpg" : svlType = "image/JPEG"
Case "jpeg" : svlType = "image/JPEG"
Case "png" : svlType = "image/png"
Case "doc" : svlType = "Application/msword" ' (for Microsoft Word files)
Case "xls" : svlType = "Application/x-msexcel" '(for Microsoft Excel files)
End Select

HttpContext.Current.Response.ContentType =svlType
HttpContext.Current.Response.write(YourVariable)

YourVariable is the variable which holds data.

In case while saving if you expect the file to be saved in a
filename you specify You can use
HttpContext.Current.Response.AppendHeader("Content-disposition",
"attachment; filename=" & myFileName)
In the case with FileName, use it as follows:


HttpContext.Current.Response.ContentType =svlType
HttpContext.Current.Response.AppendHeader("Content-disposition",
"attachment; filename=" & myFileName)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top