Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Export to Excel (Default File Type - Excel)

Reply
Thread Tools

Export to Excel (Default File Type - Excel)

 
 
=?Utf-8?B?SGVtYW50IFNpcGFoaW1hbGFuaQ==?=
Guest
Posts: n/a
 
      04-24-2006
The following piece of code is being used to export HTML to excel.

HttpContext.Current.Response.ContentType = "application/vnd.ms-excel"
HttpContext.Current.Response.AddHeader("content-disposition",
"attachment;filename=ABC.xls")
HttpContext.Current.Response.Write(strHTML)
HttpContext.Current.Response.End()

However when the user tries to save it the Default File Type is Web
Page(*.htm; *.html)
How do we change the Default File Type to Excel
 
Reply With Quote
 
 
 
 
Steve C. Orr [MVP, MCSD]
Guest
Posts: n/a
 
      04-24-2006
Try putting a Response.Clear() line at the beggining of your code block.

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net


"Hemant Sipahimalani" <Hemant http://www.velocityreviews.com/forums/(E-Mail Removed)> wrote
in message news:(E-Mail Removed)...
> The following piece of code is being used to export HTML to excel.
>
> HttpContext.Current.Response.ContentType = "application/vnd.ms-excel"
> HttpContext.Current.Response.AddHeader("content-disposition",
> "attachment;filename=ABC.xls")
> HttpContext.Current.Response.Write(strHTML)
> HttpContext.Current.Response.End()
>
> However when the user tries to save it the Default File Type is Web
> Page(*.htm; *.html)
> How do we change the Default File Type to Excel



 
Reply With Quote
 
 
 
 
=?Utf-8?B?SGVtYW50IFNpcGFoaW1hbGFuaQ==?=
Guest
Posts: n/a
 
      04-25-2006
Steve,
Thank you for the prompt reply. Response.Clear does not help though.
Listing out the full piece of code for better clarity.

Dim strFileName As String
Dim strHTML As String
Dim strAddInfo As String

HttpContext.Current.Response.Clear()
HttpContext.Current.Response.ContentType = "application/vnd.ms-excel"
strReportName = "EXPORT REPORT"
strFileName = "ABC.xls"
strAddInfo = "Additional Info"
strHTML = GetGHTML() 'This is responsible for getting report in HTML format
HttpContext.Current.Response.AddHeader("content-disposition",
"attachment;filename=" & strFileName)
HttpContext.Current.Response.Charset = ""
HttpContext.Current.Response.Write("<h4>" & strReportName & "</h4>")
HttpContext.Current.Response.Write(strAddInfo)
HttpContext.Current.Response.Write("<br><br>")
HttpContext.Current.Response.Write(strHTML)
HttpContext.Current.Response.End()
Hemant
"Steve C. Orr [MVP, MCSD]" wrote:

> Try putting a Response.Clear() line at the beggining of your code block.
>
> --
> I hope this helps,
> Steve C. Orr, MCSD, MVP
> http://SteveOrr.net
>
>
> "Hemant Sipahimalani" <Hemant (E-Mail Removed)> wrote
> in message news:(E-Mail Removed)...
> > The following piece of code is being used to export HTML to excel.
> >
> > HttpContext.Current.Response.ContentType = "application/vnd.ms-excel"
> > HttpContext.Current.Response.AddHeader("content-disposition",
> > "attachment;filename=ABC.xls")
> > HttpContext.Current.Response.Write(strHTML)
> > HttpContext.Current.Response.End()
> >
> > However when the user tries to save it the Default File Type is Web
> > Page(*.htm; *.html)
> > How do we change the Default File Type to Excel

>
>
>

 
Reply With Quote
 
Jeff Dillon
Guest
Posts: n/a
 
      04-25-2006
We have used this code:

objHttpContext.Response.Clear()
objHttpContext.Response.Buffer = True
objHttpContext.Response.ContentEncoding = System.Text.Encoding.UTF8
objHttpContext.Response.ContentType = "application/vnd.ms-excel"
objHttpContext.Response.AddHeader("Content-disposition",
"attachment;filename=export.xls")
objHttpContext.Response.Charset = ""

"Hemant Sipahimalani" <Hemant (E-Mail Removed)> wrote
in message news:(E-Mail Removed)...
> The following piece of code is being used to export HTML to excel.
>
> HttpContext.Current.Response.ContentType = "application/vnd.ms-excel"
> HttpContext.Current.Response.AddHeader("content-disposition",
> "attachment;filename=ABC.xls")
> HttpContext.Current.Response.Write(strHTML)
> HttpContext.Current.Response.End()
>
> However when the user tries to save it the Default File Type is Web
> Page(*.htm; *.html)
> How do we change the Default File Type to Excel



 
Reply With Quote
 
=?Utf-8?B?SGVtYW50IFNpcGFoaW1hbGFuaQ==?=
Guest
Posts: n/a
 
      04-26-2006
Thanks Jeff ,
but this still does not show the default File Type as xls when the user
tries to save the file.
Hemant
"Jeff Dillon" wrote:

> We have used this code:
>
> objHttpContext.Response.Clear()
> objHttpContext.Response.Buffer = True
> objHttpContext.Response.ContentEncoding = System.Text.Encoding.UTF8
> objHttpContext.Response.ContentType = "application/vnd.ms-excel"
> objHttpContext.Response.AddHeader("Content-disposition",
> "attachment;filename=export.xls")
> objHttpContext.Response.Charset = ""
>
> "Hemant Sipahimalani" <Hemant (E-Mail Removed)> wrote
> in message news:(E-Mail Removed)...
> > The following piece of code is being used to export HTML to excel.
> >
> > HttpContext.Current.Response.ContentType = "application/vnd.ms-excel"
> > HttpContext.Current.Response.AddHeader("content-disposition",
> > "attachment;filename=ABC.xls")
> > HttpContext.Current.Response.Write(strHTML)
> > HttpContext.Current.Response.End()
> >
> > However when the user tries to save it the Default File Type is Web
> > Page(*.htm; *.html)
> > How do we change the Default File Type to Excel

>
>
>

 
Reply With Quote
 
Jeff Dillon
Guest
Posts: n/a
 
      04-26-2006
Well, it does for us, for every browser in the company

Jeff
"Hemant Sipahimalani" <(E-Mail Removed)> wrote
in message news:(E-Mail Removed)...
> Thanks Jeff ,
> but this still does not show the default File Type as xls when the user
> tries to save the file.
> Hemant
> "Jeff Dillon" wrote:
>
>> We have used this code:
>>
>> objHttpContext.Response.Clear()
>> objHttpContext.Response.Buffer = True
>> objHttpContext.Response.ContentEncoding = System.Text.Encoding.UTF8
>> objHttpContext.Response.ContentType = "application/vnd.ms-excel"
>> objHttpContext.Response.AddHeader("Content-disposition",
>> "attachment;filename=export.xls")
>> objHttpContext.Response.Charset = ""
>>
>> "Hemant Sipahimalani" <Hemant (E-Mail Removed)>
>> wrote
>> in message news:(E-Mail Removed)...
>> > The following piece of code is being used to export HTML to excel.
>> >
>> > HttpContext.Current.Response.ContentType = "application/vnd.ms-excel"
>> > HttpContext.Current.Response.AddHeader("content-disposition",
>> > "attachment;filename=ABC.xls")
>> > HttpContext.Current.Response.Write(strHTML)
>> > HttpContext.Current.Response.End()
>> >
>> > However when the user tries to save it the Default File Type is Web
>> > Page(*.htm; *.html)
>> > How do we change the Default File Type to Excel

>>
>>
>>



 
Reply With Quote
 
Jeff Dillon
Guest
Posts: n/a
 
      04-26-2006
Put this all by itself in test.aspx:

<%

Response.Clear()
Response.Buffer = True
Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader("Content-disposition", "attachment;filename=export.xls")
Response.Charset = ""
Response.Write("Hello world")
Response.End()

%>

"Hemant Sipahimalani" <(E-Mail Removed)> wrote
in message news:(E-Mail Removed)...
> Thanks Jeff ,
> but this still does not show the default File Type as xls when the user
> tries to save the file.
> Hemant
> "Jeff Dillon" wrote:
>
>> We have used this code:
>>
>> objHttpContext.Response.Clear()
>> objHttpContext.Response.Buffer = True
>> objHttpContext.Response.ContentEncoding = System.Text.Encoding.UTF8
>> objHttpContext.Response.ContentType = "application/vnd.ms-excel"
>> objHttpContext.Response.AddHeader("Content-disposition",
>> "attachment;filename=export.xls")
>> objHttpContext.Response.Charset = ""
>>
>> "Hemant Sipahimalani" <Hemant (E-Mail Removed)>
>> wrote
>> in message news:(E-Mail Removed)...
>> > The following piece of code is being used to export HTML to excel.
>> >
>> > HttpContext.Current.Response.ContentType = "application/vnd.ms-excel"
>> > HttpContext.Current.Response.AddHeader("content-disposition",
>> > "attachment;filename=ABC.xls")
>> > HttpContext.Current.Response.Write(strHTML)
>> > HttpContext.Current.Response.End()
>> >
>> > However when the user tries to save it the Default File Type is Web
>> > Page(*.htm; *.html)
>> > How do we change the Default File Type to Excel

>>
>>
>>



 
Reply With Quote
 
=?Utf-8?B?SGVtYW50IFNpcGFoaW1hbGFuaQ==?=
Guest
Posts: n/a
 
      04-27-2006
Jeff,
You are correct. The piece of code that you have written does show the
Exported file as "Text (tab delimited) (*.txt) " in the "Save as type"
dropdown when the user tries to save the excel file.
However in my case the data is in tabular format as opposed to "Hello
World".
The data that I am trying to export is similar to

strHTML = "<table><tr><td>1</td><td>2</td><td>3</td></tr></table>"

HttpContext.Current.Response.Clear()
HttpContext.Current.Response.Buffer = True
HttpContext.Current.Response.ContentType = "application/vnd.ms-excel"
HttpContext.Current.Response.AddHeader("Content-disposition",
"attachment;filename=export.xls")
HttpContext.Current.Response.Charset = ""
HttpContext.Current.Response.Write(strHTML)
HttpContext.Current.Response.End()

In this case when the user tries to save the exported excel the "Save as
Type" drop down shows the type as a "Web Page". This is something that I am
trying to avoid.

Thanks,
Hemant


"Jeff Dillon" wrote:

> Put this all by itself in test.aspx:
>
> <%
>
> Response.Clear()
> Response.Buffer = True
> Response.ContentType = "application/vnd.ms-excel"
> Response.AddHeader("Content-disposition", "attachment;filename=export.xls")
> Response.Charset = ""
> Response.Write("Hello world")
> Response.End()
>
> %>
>
> "Hemant Sipahimalani" <(E-Mail Removed)> wrote
> in message news:(E-Mail Removed)...
> > Thanks Jeff ,
> > but this still does not show the default File Type as xls when the user
> > tries to save the file.
> > Hemant
> > "Jeff Dillon" wrote:
> >
> >> We have used this code:
> >>
> >> objHttpContext.Response.Clear()
> >> objHttpContext.Response.Buffer = True
> >> objHttpContext.Response.ContentEncoding = System.Text.Encoding.UTF8
> >> objHttpContext.Response.ContentType = "application/vnd.ms-excel"
> >> objHttpContext.Response.AddHeader("Content-disposition",
> >> "attachment;filename=export.xls")
> >> objHttpContext.Response.Charset = ""
> >>
> >> "Hemant Sipahimalani" <Hemant (E-Mail Removed)>
> >> wrote
> >> in message news:(E-Mail Removed)...
> >> > The following piece of code is being used to export HTML to excel.
> >> >
> >> > HttpContext.Current.Response.ContentType = "application/vnd.ms-excel"
> >> > HttpContext.Current.Response.AddHeader("content-disposition",
> >> > "attachment;filename=ABC.xls")
> >> > HttpContext.Current.Response.Write(strHTML)
> >> > HttpContext.Current.Response.End()
> >> >
> >> > However when the user tries to save it the Default File Type is Web
> >> > Page(*.htm; *.html)
> >> > How do we change the Default File Type to Excel
> >>
> >>
> >>

>
>
>

 
Reply With Quote
 
Jeff Dillon
Guest
Posts: n/a
 
      04-27-2006
On ALL our machines, my code shows Save As Excel Sheet in the Save As dialog
popup.

Do you have Excel installed on your client machines?? Which is a requirement
of course, to save in that format.

Jeff

"Hemant Sipahimalani" <(E-Mail Removed)> wrote
in message news:(E-Mail Removed)...
> Jeff,
> You are correct. The piece of code that you have written does show the
> Exported file as "Text (tab delimited) (*.txt) " in the "Save as type"
> dropdown when the user tries to save the excel file.
> However in my case the data is in tabular format as opposed to "Hello
> World".
> The data that I am trying to export is similar to
>
> strHTML = "<table><tr><td>1</td><td>2</td><td>3</td></tr></table>"
>
> HttpContext.Current.Response.Clear()
> HttpContext.Current.Response.Buffer = True
> HttpContext.Current.Response.ContentType =
> "application/vnd.ms-excel"
> HttpContext.Current.Response.AddHeader("Content-disposition",
> "attachment;filename=export.xls")
> HttpContext.Current.Response.Charset = ""
> HttpContext.Current.Response.Write(strHTML)
> HttpContext.Current.Response.End()
>
> In this case when the user tries to save the exported excel the "Save as
> Type" drop down shows the type as a "Web Page". This is something that I
> am
> trying to avoid.
>
> Thanks,
> Hemant
>
>
> "Jeff Dillon" wrote:
>
>> Put this all by itself in test.aspx:
>>
>> <%
>>
>> Response.Clear()
>> Response.Buffer = True
>> Response.ContentType = "application/vnd.ms-excel"
>> Response.AddHeader("Content-disposition",
>> "attachment;filename=export.xls")
>> Response.Charset = ""
>> Response.Write("Hello world")
>> Response.End()
>>
>> %>
>>
>> "Hemant Sipahimalani" <(E-Mail Removed)>
>> wrote
>> in message news:(E-Mail Removed)...
>> > Thanks Jeff ,
>> > but this still does not show the default File Type as xls when the
>> > user
>> > tries to save the file.
>> > Hemant
>> > "Jeff Dillon" wrote:
>> >
>> >> We have used this code:
>> >>
>> >> objHttpContext.Response.Clear()
>> >> objHttpContext.Response.Buffer = True
>> >> objHttpContext.Response.ContentEncoding = System.Text.Encoding.UTF8
>> >> objHttpContext.Response.ContentType = "application/vnd.ms-excel"
>> >> objHttpContext.Response.AddHeader("Content-disposition",
>> >> "attachment;filename=export.xls")
>> >> objHttpContext.Response.Charset = ""
>> >>
>> >> "Hemant Sipahimalani" <Hemant (E-Mail Removed)>
>> >> wrote
>> >> in message news:(E-Mail Removed)...
>> >> > The following piece of code is being used to export HTML to excel.
>> >> >
>> >> > HttpContext.Current.Response.ContentType =
>> >> > "application/vnd.ms-excel"
>> >> > HttpContext.Current.Response.AddHeader("content-disposition",
>> >> > "attachment;filename=ABC.xls")
>> >> > HttpContext.Current.Response.Write(strHTML)
>> >> > HttpContext.Current.Response.End()
>> >> >
>> >> > However when the user tries to save it the Default File Type is Web
>> >> > Page(*.htm; *.html)
>> >> > How do we change the Default File Type to Excel
>> >>
>> >>
>> >>

>>
>>
>>



 
Reply With Quote
 
=?Utf-8?B?SGVtYW50IFNpcGFoaW1hbGFuaQ==?=
Guest
Posts: n/a
 
      04-28-2006
Jeff,
I have the following versions installed on my machine.
1. Excel - Microsoft Excel 2003 (11.5612.5606)
2. IE - 6.0.2900.2180 , SP2
Thanks,
Hemant

"Jeff Dillon" wrote:

> On ALL our machines, my code shows Save As Excel Sheet in the Save As dialog
> popup.
>
> Do you have Excel installed on your client machines?? Which is a requirement
> of course, to save in that format.
>
> Jeff
>
> "Hemant Sipahimalani" <(E-Mail Removed)> wrote
> in message news:(E-Mail Removed)...
> > Jeff,
> > You are correct. The piece of code that you have written does show the
> > Exported file as "Text (tab delimited) (*.txt) " in the "Save as type"
> > dropdown when the user tries to save the excel file.
> > However in my case the data is in tabular format as opposed to "Hello
> > World".
> > The data that I am trying to export is similar to
> >
> > strHTML = "<table><tr><td>1</td><td>2</td><td>3</td></tr></table>"
> >
> > HttpContext.Current.Response.Clear()
> > HttpContext.Current.Response.Buffer = True
> > HttpContext.Current.Response.ContentType =
> > "application/vnd.ms-excel"
> > HttpContext.Current.Response.AddHeader("Content-disposition",
> > "attachment;filename=export.xls")
> > HttpContext.Current.Response.Charset = ""
> > HttpContext.Current.Response.Write(strHTML)
> > HttpContext.Current.Response.End()
> >
> > In this case when the user tries to save the exported excel the "Save as
> > Type" drop down shows the type as a "Web Page". This is something that I
> > am
> > trying to avoid.
> >
> > Thanks,
> > Hemant
> >
> >
> > "Jeff Dillon" wrote:
> >
> >> Put this all by itself in test.aspx:
> >>
> >> <%
> >>
> >> Response.Clear()
> >> Response.Buffer = True
> >> Response.ContentType = "application/vnd.ms-excel"
> >> Response.AddHeader("Content-disposition",
> >> "attachment;filename=export.xls")
> >> Response.Charset = ""
> >> Response.Write("Hello world")
> >> Response.End()
> >>
> >> %>
> >>
> >> "Hemant Sipahimalani" <(E-Mail Removed)>
> >> wrote
> >> in message news:(E-Mail Removed)...
> >> > Thanks Jeff ,
> >> > but this still does not show the default File Type as xls when the
> >> > user
> >> > tries to save the file.
> >> > Hemant
> >> > "Jeff Dillon" wrote:
> >> >
> >> >> We have used this code:
> >> >>
> >> >> objHttpContext.Response.Clear()
> >> >> objHttpContext.Response.Buffer = True
> >> >> objHttpContext.Response.ContentEncoding = System.Text.Encoding.UTF8
> >> >> objHttpContext.Response.ContentType = "application/vnd.ms-excel"
> >> >> objHttpContext.Response.AddHeader("Content-disposition",
> >> >> "attachment;filename=export.xls")
> >> >> objHttpContext.Response.Charset = ""
> >> >>
> >> >> "Hemant Sipahimalani" <Hemant (E-Mail Removed)>
> >> >> wrote
> >> >> in message news:(E-Mail Removed)...
> >> >> > The following piece of code is being used to export HTML to excel.
> >> >> >
> >> >> > HttpContext.Current.Response.ContentType =
> >> >> > "application/vnd.ms-excel"
> >> >> > HttpContext.Current.Response.AddHeader("content-disposition",
> >> >> > "attachment;filename=ABC.xls")
> >> >> > HttpContext.Current.Response.Write(strHTML)
> >> >> > HttpContext.Current.Response.End()
> >> >> >
> >> >> > However when the user tries to save it the Default File Type is Web
> >> >> > Page(*.htm; *.html)
> >> >> > How do we change the Default File Type to Excel
> >> >>
> >> >>
> >> >>
> >>
> >>
> >>

>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
save a flat export data file as an excel file c676228 ASP General 3 07-17-2008 06:02 PM
Problem with Excel reports ::::Excel 2003 Migration To Excel 2007 =?Utf-8?B?c2hhc2hhbmsga3Vsa2Fybmk=?= ASP .Net 15 10-24-2007 01:34 PM
Export to excel in asp.net using excel template Grey ASP .Net 4 10-17-2007 08:08 AM
using Microsoft Excel image for Export to Excel button =?Utf-8?B?U3JpZGhhcg==?= ASP .Net 0 12-09-2005 08:58 PM
Invalid export DLL or export format =?Utf-8?B?RGF2aWQgVmFsbGU=?= ASP .Net 0 10-29-2003 11:46 AM



Advertisments