Export to Excel (Default File Type - Excel)

Discussion in 'ASP .Net' started by =?Utf-8?B?SGVtYW50IFNpcGFoaW1hbGFuaQ==?=, Apr 24, 2006.

  1. 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
    =?Utf-8?B?SGVtYW50IFNpcGFoaW1hbGFuaQ==?=, Apr 24, 2006
    #1
    1. Advertising

  2. 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 > wrote
    in message news:...
    > 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
    Steve C. Orr [MVP, MCSD], Apr 24, 2006
    #2
    1. Advertising

  3. 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 > wrote
    > in message news:...
    > > 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

    >
    >
    >
    =?Utf-8?B?SGVtYW50IFNpcGFoaW1hbGFuaQ==?=, Apr 25, 2006
    #3
  4. =?Utf-8?B?SGVtYW50IFNpcGFoaW1hbGFuaQ==?=

    Jeff Dillon Guest

    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 > wrote
    in message news:...
    > 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
    Jeff Dillon, Apr 25, 2006
    #4
  5. 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 > wrote
    > in message news:...
    > > 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

    >
    >
    >
    =?Utf-8?B?SGVtYW50IFNpcGFoaW1hbGFuaQ==?=, Apr 26, 2006
    #5
  6. =?Utf-8?B?SGVtYW50IFNpcGFoaW1hbGFuaQ==?=

    Jeff Dillon Guest

    Well, it does for us, for every browser in the company

    Jeff
    "Hemant Sipahimalani" <> wrote
    in message news:...
    > 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 >
    >> wrote
    >> in message news:...
    >> > 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

    >>
    >>
    >>
    Jeff Dillon, Apr 26, 2006
    #6
  7. =?Utf-8?B?SGVtYW50IFNpcGFoaW1hbGFuaQ==?=

    Jeff Dillon Guest

    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" <> wrote
    in message news:...
    > 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 >
    >> wrote
    >> in message news:...
    >> > 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

    >>
    >>
    >>
    Jeff Dillon, Apr 26, 2006
    #7
  8. 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" <> wrote
    > in message news:...
    > > 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 >
    > >> wrote
    > >> in message news:...
    > >> > 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
    > >>
    > >>
    > >>

    >
    >
    >
    =?Utf-8?B?SGVtYW50IFNpcGFoaW1hbGFuaQ==?=, Apr 27, 2006
    #8
  9. =?Utf-8?B?SGVtYW50IFNpcGFoaW1hbGFuaQ==?=

    Jeff Dillon Guest

    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" <> wrote
    in message news:...
    > 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" <>
    >> wrote
    >> in message news:...
    >> > 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 >
    >> >> wrote
    >> >> in message news:...
    >> >> > 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
    >> >>
    >> >>
    >> >>

    >>
    >>
    >>
    Jeff Dillon, Apr 27, 2006
    #9
  10. 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" <> wrote
    > in message news:...
    > > 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" <>
    > >> wrote
    > >> in message news:...
    > >> > 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 >
    > >> >> wrote
    > >> >> in message news:...
    > >> >> > 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
    > >> >>
    > >> >>
    > >> >>
    > >>
    > >>
    > >>

    >
    >
    >
    =?Utf-8?B?SGVtYW50IFNpcGFoaW1hbGFuaQ==?=, Apr 28, 2006
    #10
  11. =?Utf-8?B?SGVtYW50IFNpcGFoaW1hbGFuaQ==?=

    Jeff Dillon Guest

    I'm wondering if it's a mime type setting on your server..

    Jeff

    "Hemant Sipahimalani" <> wrote
    in message news:...
    > 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" <>
    >> wrote
    >> in message news:...
    >> > 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" <>
    >> >> wrote
    >> >> in message news:...
    >> >> > 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
    >> >> >> >
    >> >> >> wrote
    >> >> >> in message
    >> >> >> news:...
    >> >> >> > 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
    >> >> >>
    >> >> >>
    >> >> >>
    >> >>
    >> >>
    >> >>

    >>
    >>
    >>
    Jeff Dillon, Apr 28, 2006
    #11
  12. 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" <> wrote
    > in message news:...
    > > 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" <>
    > >> wrote
    > >> in message news:...
    > >> > 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" <>
    > >> >> wrote
    > >> >> in message news:...
    > >> >> > 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
    > >> >> >> >
    > >> >> >> wrote
    > >> >> >> in message
    > >> >> >> news:...
    > >> >> >> > 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
    > >> >> >>
    > >> >> >>
    > >> >> >>
    > >> >>
    > >> >>
    > >> >>
    > >>
    > >>
    > >>

    >
    >
    >
    =?Utf-8?B?SGVtYW50IFNpcGFoaW1hbGFuaQ==?=, May 5, 2006
    #12
  13. 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" <> wrote
    > > in message news:...
    > > > 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" <>
    > > >> wrote
    > > >> in message news:...
    > > >> > 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" <>
    > > >> >> wrote
    > > >> >> in message news:...
    > > >> >> > 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
    > > >> >> >> >
    > > >> >> >> wrote
    > > >> >> >> in message
    > > >> >> >> news:...
    > > >> >> >> > 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
    > > >> >> >>
    > > >> >> >>
    > > >> >> >>
    > > >> >>
    > > >> >>
    > > >> >>
    > > >>
    > > >>
    > > >>

    > >
    > >
    > >
    =?Utf-8?B?SEFSSSBQUkFTRCBCQVJV?=, Jun 19, 2006
    #13
  14. 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" <> wrote
    > > > in message news:...
    > > > > 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" <>
    > > > >> wrote
    > > > >> in message news:...
    > > > >> > 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" <>
    > > > >> >> wrote
    > > > >> >> in message news:...
    > > > >> >> > 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
    > > > >> >> >> >
    > > > >> >> >> wrote
    > > > >> >> >> in message
    > > > >> >> >> news:...
    > > > >> >> >> > 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
    > > > >> >> >>
    > > > >> >> >>
    > > > >> >> >>
    > > > >> >>
    > > > >> >>
    > > > >> >>
    > > > >>
    > > > >>
    > > > >>
    > > >
    > > >
    > > >
    =?Utf-8?B?SGVtYW50IFNpcGFoaW1hbGFuaQ==?=, Jun 21, 2006
    #14
  15. =?Utf-8?B?SGVtYW50IFNpcGFoaW1hbGFuaQ==?=

    ckv

    Joined:
    Oct 16, 2006
    Messages:
    1
    Viewstate

    I ran across the same issue where the default file type was HTML but worked fine on other pages. Turned out I had turned off the viewstate on the page to try to help performance. Once viewstate was turned back on it worked fine.
    ckv, Oct 16, 2006
    #15
  16. =?Utf-8?B?SGVtYW50IFNpcGFoaW1hbGFuaQ==?=

    syed hassan

    Joined:
    May 21, 2009
    Messages:
    1
    Hi i have used a java code in an application
    response.setContentType("application/vnd.ms-excel");
    response.setHeader("Content-disposition","inline; filename=report.xls");

    to export a java code to an excel. this is working fine.
    When i click on the 'save' button in the popup, iam able to save the file. but when i click on 'open' button and try to save the spreadsheet once its opened, the file type i defaulted as txt, Could you please suggest ways for the same so that the default type should remain xls
    syed hassan, May 21, 2009
    #16
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?RGF2aWQgVmFsbGU=?=

    Invalid export DLL or export format

    =?Utf-8?B?RGF2aWQgVmFsbGU=?=, Oct 29, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    3,617
    =?Utf-8?B?RGF2aWQgVmFsbGU=?=
    Oct 29, 2003
  2. =?Utf-8?B?U3JpZGhhcg==?=

    using Microsoft Excel image for Export to Excel button

    =?Utf-8?B?U3JpZGhhcg==?=, Dec 9, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    3,104
    =?Utf-8?B?U3JpZGhhcg==?=
    Dec 9, 2005
  3. Grey
    Replies:
    4
    Views:
    1,971
    Mark Rae [MVP]
    Oct 17, 2007
  4. c676228
    Replies:
    3
    Views:
    344
    Mike Brind [MVP]
    Jul 17, 2008
  5. Maarten Porters
    Replies:
    1
    Views:
    429
    Florian Gilcher
    Jul 28, 2008
Loading...

Share This Page