By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,356 Members | 2,752 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,356 IT Pros & Developers. It's quick & easy.

Export to Excel (Default File Type - Excel)

P: n/a
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
Apr 24 '06 #1
Share this Question
Share on Google+
13 Replies


P: n/a
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 Si**********@discussions.microsoft.com> wrote
in message news:C0**********************************@microsof t.com...
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

Apr 24 '06 #2

P: n/a
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 Si**********@discussions.microsoft.com> wrote
in message news:C0**********************************@microsof t.com...
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


Apr 25 '06 #3

P: n/a
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 Si**********@discussions.microsoft.com> wrote
in message news:C0**********************************@microsof t.com...
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

Apr 25 '06 #4

P: n/a
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 Si**********@discussions.microsoft.com> wrote
in message news:C0**********************************@microsof t.com...
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


Apr 26 '06 #5

P: n/a
Well, it does for us, for every browser in the company

Jeff
"Hemant Sipahimalani" <He****************@discussions.microsoft.com> wrote
in message news:8B**********************************@microsof t.com...
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 Si**********@discussions.microsoft.com>
wrote
in message news:C0**********************************@microsof t.com...
> 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


Apr 26 '06 #6

P: n/a
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" <He****************@discussions.microsoft.com> wrote
in message news:8B**********************************@microsof t.com...
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 Si**********@discussions.microsoft.com>
wrote
in message news:C0**********************************@microsof t.com...
> 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


Apr 26 '06 #7

P: n/a
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" <He****************@discussions.microsoft.com> wrote
in message news:8B**********************************@microsof t.com...
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 Si**********@discussions.microsoft.com>
wrote
in message news:C0**********************************@microsof t.com...
> 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


Apr 27 '06 #8

P: n/a
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" <He****************@discussions.microsoft.com> wrote
in message news:E9**********************************@microsof t.com...
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" <He****************@discussions.microsoft.com>
wrote
in message news:8B**********************************@microsof t.com...
> 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 Si**********@discussions.microsoft.com>
>> wrote
>> in message news:C0**********************************@microsof t.com...
>> > 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
>>
>>
>>


Apr 27 '06 #9

P: n/a
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" <He****************@discussions.microsoft.com> wrote
in message news:E9**********************************@microsof t.com...
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" <He****************@discussions.microsoft.com>
wrote
in message news:8B**********************************@microsof t.com...
> 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 Si**********@discussions.microsoft.com>
>> wrote
>> in message news:C0**********************************@microsof t.com...
>> > 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
>>
>>
>>


Apr 28 '06 #10

P: n/a
I'm wondering if it's a mime type setting on your server..

Jeff

"Hemant Sipahimalani" <He****************@discussions.microsoft.com> wrote
in message news:42**********************************@microsof t.com...
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" <He****************@discussions.microsoft.com>
wrote
in message news:E9**********************************@microsof t.com...
> 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" <He****************@discussions.microsoft.com>
>> wrote
>> in message news:8B**********************************@microsof t.com...
>> > 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
>> >> Si**********@discussions.microsoft.com>
>> >> wrote
>> >> in message
>> >> news:C0**********************************@microsof t.com...
>> >> > 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
>> >>
>> >>
>> >>
>>
>>
>>


Apr 28 '06 #11

P: n/a
Jeff,
MIME settings are set up to open a file with xls in Excel sheet. This is
exactly what the code does. It is only when you try to save the file, the
"Save as Type" is a "Web Page" as opposed to "xls".
Is it possible to send across the link to the test report on your
application across to me? Curious to see how it works against my Test bed.
Thanks,
Hemant
"Jeff Dillon" wrote:
I'm wondering if it's a mime type setting on your server..

Jeff

"Hemant Sipahimalani" <He****************@discussions.microsoft.com> wrote
in message news:42**********************************@microsof t.com...
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" <He****************@discussions.microsoft.com>
wrote
in message news:E9**********************************@microsof t.com...
> 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" <He****************@discussions.microsoft.com>
>> wrote
>> in message news:8B**********************************@microsof t.com...
>> > 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
>> >> Si**********@discussions.microsoft.com>
>> >> wrote
>> >> in message
>> >> news:C0**********************************@microsof t.com...
>> >> > 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
>> >>
>> >>
>> >>
>>
>>
>>


May 5 '06 #12

P: n/a
Hemant,
We also having same issue with Export to Excel, tried all possible code
solutions but didn't worked out,
Curious to know if you would have got solution as you also facing same issue.
Plz let me know if have any solution..

"Hemant Sipahimalani" wrote:
Jeff,
MIME settings are set up to open a file with xls in Excel sheet. This is
exactly what the code does. It is only when you try to save the file, the
"Save as Type" is a "Web Page" as opposed to "xls".
Is it possible to send across the link to the test report on your
application across to me? Curious to see how it works against my Test bed.
Thanks,
Hemant
"Jeff Dillon" wrote:
I'm wondering if it's a mime type setting on your server..

Jeff

"Hemant Sipahimalani" <He****************@discussions.microsoft.com> wrote
in message news:42**********************************@microsof t.com...
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" <He****************@discussions.microsoft.com>
> wrote
> in message news:E9**********************************@microsof t.com...
> > 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" <He****************@discussions.microsoft.com>
> >> wrote
> >> in message news:8B**********************************@microsof t.com...
> >> > 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
> >> >> Si**********@discussions.microsoft.com>
> >> >> wrote
> >> >> in message
> >> >> news:C0**********************************@microsof t.com...
> >> >> > 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
> >> >>
> >> >>
> >> >>
> >>
> >>
> >>
>
>
>


Jun 19 '06 #13

P: n/a
Hari,
There is no solution that I could find out. The workaround for this is to
use the Excel Object and create an excel on the server itself, which will
have to be ultimately downloaded on the client. But this method has it's own
limitations.
Regards,
Hemant
"HARI PRASD BARU" wrote:
Hemant,
We also having same issue with Export to Excel, tried all possible code
solutions but didn't worked out,
Curious to know if you would have got solution as you also facing same issue.
Plz let me know if have any solution..

"Hemant Sipahimalani" wrote:
Jeff,
MIME settings are set up to open a file with xls in Excel sheet. This is
exactly what the code does. It is only when you try to save the file, the
"Save as Type" is a "Web Page" as opposed to "xls".
Is it possible to send across the link to the test report on your
application across to me? Curious to see how it works against my Test bed.
Thanks,
Hemant
"Jeff Dillon" wrote:
I'm wondering if it's a mime type setting on your server..

Jeff

"Hemant Sipahimalani" <He****************@discussions.microsoft.com> wrote
in message news:42**********************************@microsof t.com...
> 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" <He****************@discussions.microsoft.com>
>> wrote
>> in message news:E9**********************************@microsof t.com...
>> > 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" <He****************@discussions.microsoft.com>
>> >> wrote
>> >> in message news:8B**********************************@microsof t.com...
>> >> > 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
>> >> >> Si**********@discussions.microsoft.com>
>> >> >> wrote
>> >> >> in message
>> >> >> news:C0**********************************@microsof t.com...
>> >> >> > 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
>> >> >>
>> >> >>
>> >> >>
>> >>
>> >>
>> >>
>>
>>
>>

Jun 21 '06 #14

This discussion thread is closed

Replies have been disabled for this discussion.