471,079 Members | 951 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,079 software developers and data experts.

Dynamically creating .xls file.


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?

Nov 18 '05 #1
2 4387
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)

"Asha" wrote:

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?

Nov 18 '05 #2
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) HttpContext.Current.Response.write(YourVariable)

"Asha" wrote:

Greetings,

Ive 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?

Nov 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Billy Cormic | last post: by
7 posts views Thread by Selden McCabe | last post: by
2 posts views Thread by epigram | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.