473,847 Members | 1,534 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Export to Excel (Default File Type - Excel)

The following piece of code is being used to export HTML to excel.

HttpContext.Cur rent.Response.C ontentType = "applicatio n/vnd.ms-excel"
HttpContext.Cur rent.Response.A ddHeader("conte nt-disposition",
"attachment;fil ename=ABC.xls")
HttpContext.Cur rent.Response.W rite(strHTML)
HttpContext.Cur rent.Response.E nd()

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
13 13265
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**********@di scussions.micro soft.com> wrote
in message news:C0******** *************** ***********@mic rosoft.com...
The following piece of code is being used to export HTML to excel.

HttpContext.Cur rent.Response.C ontentType = "applicatio n/vnd.ms-excel"
HttpContext.Cur rent.Response.A ddHeader("conte nt-disposition",
"attachment;fil ename=ABC.xls")
HttpContext.Cur rent.Response.W rite(strHTML)
HttpContext.Cur rent.Response.E nd()

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
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.Cur rent.Response.C lear()
HttpContext.Cur rent.Response.C ontentType = "applicatio n/vnd.ms-excel"
strReportName = "EXPORT REPORT"
strFileName = "ABC.xls"
strAddInfo = "Additional Info"
strHTML = GetGHTML() 'This is responsible for getting report in HTML format
HttpContext.Cur rent.Response.A ddHeader("conte nt-disposition",
"attachment;fil ename=" & strFileName)
HttpContext.Cur rent.Response.C harset = ""
HttpContext.Cur rent.Response.W rite("<h4>" & strReportName & "</h4>")
HttpContext.Cur rent.Response.W rite(strAddInfo )
HttpContext.Cur rent.Response.W rite("<br><br>" )
HttpContext.Cur rent.Response.W rite(strHTML)
HttpContext.Cur rent.Response.E nd()
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**********@di scussions.micro soft.com> wrote
in message news:C0******** *************** ***********@mic rosoft.com...
The following piece of code is being used to export HTML to excel.

HttpContext.Cur rent.Response.C ontentType = "applicatio n/vnd.ms-excel"
HttpContext.Cur rent.Response.A ddHeader("conte nt-disposition",
"attachment;fil ename=ABC.xls")
HttpContext.Cur rent.Response.W rite(strHTML)
HttpContext.Cur rent.Response.E nd()

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
We have used this code:

objHttpContext. Response.Clear( )
objHttpContext. Response.Buffer = True
objHttpContext. Response.Conten tEncoding = System.Text.Enc oding.UTF8
objHttpContext. Response.Conten tType = "applicatio n/vnd.ms-excel"
objHttpContext. Response.AddHea der("Content-disposition",
"attachment;fil ename=export.xl s")
objHttpContext. Response.Charse t = ""

"Hemant Sipahimalani" <Hemant Si**********@di scussions.micro soft.com> wrote
in message news:C0******** *************** ***********@mic rosoft.com...
The following piece of code is being used to export HTML to excel.

HttpContext.Cur rent.Response.C ontentType = "applicatio n/vnd.ms-excel"
HttpContext.Cur rent.Response.A ddHeader("conte nt-disposition",
"attachment;fil ename=ABC.xls")
HttpContext.Cur rent.Response.W rite(strHTML)
HttpContext.Cur rent.Response.E nd()

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
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.Conten tEncoding = System.Text.Enc oding.UTF8
objHttpContext. Response.Conten tType = "applicatio n/vnd.ms-excel"
objHttpContext. Response.AddHea der("Content-disposition",
"attachment;fil ename=export.xl s")
objHttpContext. Response.Charse t = ""

"Hemant Sipahimalani" <Hemant Si**********@di scussions.micro soft.com> wrote
in message news:C0******** *************** ***********@mic rosoft.com...
The following piece of code is being used to export HTML to excel.

HttpContext.Cur rent.Response.C ontentType = "applicatio n/vnd.ms-excel"
HttpContext.Cur rent.Response.A ddHeader("conte nt-disposition",
"attachment;fil ename=ABC.xls")
HttpContext.Cur rent.Response.W rite(strHTML)
HttpContext.Cur rent.Response.E nd()

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
Well, it does for us, for every browser in the company

Jeff
"Hemant Sipahimalani" <He************ ****@discussion s.microsoft.com > wrote
in message news:8B******** *************** ***********@mic rosoft.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.Conten tEncoding = System.Text.Enc oding.UTF8
objHttpContext. Response.Conten tType = "applicatio n/vnd.ms-excel"
objHttpContext. Response.AddHea der("Content-disposition",
"attachment;fil ename=export.xl s")
objHttpContext. Response.Charse t = ""

"Hemant Sipahimalani" <Hemant Si**********@di scussions.micro soft.com>
wrote
in message news:C0******** *************** ***********@mic rosoft.com...
> The following piece of code is being used to export HTML to excel.
>
> HttpContext.Cur rent.Response.C ontentType = "applicatio n/vnd.ms-excel"
> HttpContext.Cur rent.Response.A ddHeader("conte nt-disposition",
> "attachment;fil ename=ABC.xls")
> HttpContext.Cur rent.Response.W rite(strHTML)
> HttpContext.Cur rent.Response.E nd()
>
> 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
Put this all by itself in test.aspx:

<%

Response.Clear( )
Response.Buffer = True
Response.Conten tType = "applicatio n/vnd.ms-excel"
Response.AddHea der("Content-disposition", "attachment;fil ename=export.xl s")
Response.Charse t = ""
Response.Write( "Hello world")
Response.End()

%>

"Hemant Sipahimalani" <He************ ****@discussion s.microsoft.com > wrote
in message news:8B******** *************** ***********@mic rosoft.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.Conten tEncoding = System.Text.Enc oding.UTF8
objHttpContext. Response.Conten tType = "applicatio n/vnd.ms-excel"
objHttpContext. Response.AddHea der("Content-disposition",
"attachment;fil ename=export.xl s")
objHttpContext. Response.Charse t = ""

"Hemant Sipahimalani" <Hemant Si**********@di scussions.micro soft.com>
wrote
in message news:C0******** *************** ***********@mic rosoft.com...
> The following piece of code is being used to export HTML to excel.
>
> HttpContext.Cur rent.Response.C ontentType = "applicatio n/vnd.ms-excel"
> HttpContext.Cur rent.Response.A ddHeader("conte nt-disposition",
> "attachment;fil ename=ABC.xls")
> HttpContext.Cur rent.Response.W rite(strHTML)
> HttpContext.Cur rent.Response.E nd()
>
> 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
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.Cur rent.Response.C lear()
HttpContext.Cur rent.Response.B uffer = True
HttpContext.Cur rent.Response.C ontentType = "applicatio n/vnd.ms-excel"
HttpContext.Cur rent.Response.A ddHeader("Conte nt-disposition",
"attachment;fil ename=export.xl s")
HttpContext.Cur rent.Response.C harset = ""
HttpContext.Cur rent.Response.W rite(strHTML)
HttpContext.Cur rent.Response.E nd()

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.Conten tType = "applicatio n/vnd.ms-excel"
Response.AddHea der("Content-disposition", "attachment;fil ename=export.xl s")
Response.Charse t = ""
Response.Write( "Hello world")
Response.End()

%>

"Hemant Sipahimalani" <He************ ****@discussion s.microsoft.com > wrote
in message news:8B******** *************** ***********@mic rosoft.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.Conten tEncoding = System.Text.Enc oding.UTF8
objHttpContext. Response.Conten tType = "applicatio n/vnd.ms-excel"
objHttpContext. Response.AddHea der("Content-disposition",
"attachment;fil ename=export.xl s")
objHttpContext. Response.Charse t = ""

"Hemant Sipahimalani" <Hemant Si**********@di scussions.micro soft.com>
wrote
in message news:C0******** *************** ***********@mic rosoft.com...
> The following piece of code is being used to export HTML to excel.
>
> HttpContext.Cur rent.Response.C ontentType = "applicatio n/vnd.ms-excel"
> HttpContext.Cur rent.Response.A ddHeader("conte nt-disposition",
> "attachment;fil ename=ABC.xls")
> HttpContext.Cur rent.Response.W rite(strHTML)
> HttpContext.Cur rent.Response.E nd()
>
> 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
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************ ****@discussion s.microsoft.com > wrote
in message news:E9******** *************** ***********@mic rosoft.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.Cur rent.Response.C lear()
HttpContext.Cur rent.Response.B uffer = True
HttpContext.Cur rent.Response.C ontentType =
"applicatio n/vnd.ms-excel"
HttpContext.Cur rent.Response.A ddHeader("Conte nt-disposition",
"attachment;fil ename=export.xl s")
HttpContext.Cur rent.Response.C harset = ""
HttpContext.Cur rent.Response.W rite(strHTML)
HttpContext.Cur rent.Response.E nd()

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.Conten tType = "applicatio n/vnd.ms-excel"
Response.AddHea der("Content-disposition",
"attachment;fil ename=export.xl s")
Response.Charse t = ""
Response.Write( "Hello world")
Response.End()

%>

"Hemant Sipahimalani" <He************ ****@discussion s.microsoft.com >
wrote
in message news:8B******** *************** ***********@mic rosoft.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.Conten tEncoding = System.Text.Enc oding.UTF8
>> objHttpContext. Response.Conten tType = "applicatio n/vnd.ms-excel"
>> objHttpContext. Response.AddHea der("Content-disposition",
>> "attachment;fil ename=export.xl s")
>> objHttpContext. Response.Charse t = ""
>>
>> "Hemant Sipahimalani" <Hemant Si**********@di scussions.micro soft.com>
>> wrote
>> in message news:C0******** *************** ***********@mic rosoft.com...
>> > The following piece of code is being used to export HTML to excel.
>> >
>> > HttpContext.Cur rent.Response.C ontentType =
>> > "applicatio n/vnd.ms-excel"
>> > HttpContext.Cur rent.Response.A ddHeader("conte nt-disposition",
>> > "attachment;fil ename=ABC.xls")
>> > HttpContext.Cur rent.Response.W rite(strHTML)
>> > HttpContext.Cur rent.Response.E nd()
>> >
>> > 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
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************ ****@discussion s.microsoft.com > wrote
in message news:E9******** *************** ***********@mic rosoft.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.Cur rent.Response.C lear()
HttpContext.Cur rent.Response.B uffer = True
HttpContext.Cur rent.Response.C ontentType =
"applicatio n/vnd.ms-excel"
HttpContext.Cur rent.Response.A ddHeader("Conte nt-disposition",
"attachment;fil ename=export.xl s")
HttpContext.Cur rent.Response.C harset = ""
HttpContext.Cur rent.Response.W rite(strHTML)
HttpContext.Cur rent.Response.E nd()

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.Conten tType = "applicatio n/vnd.ms-excel"
Response.AddHea der("Content-disposition",
"attachment;fil ename=export.xl s")
Response.Charse t = ""
Response.Write( "Hello world")
Response.End()

%>

"Hemant Sipahimalani" <He************ ****@discussion s.microsoft.com >
wrote
in message news:8B******** *************** ***********@mic rosoft.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.Conten tEncoding = System.Text.Enc oding.UTF8
>> objHttpContext. Response.Conten tType = "applicatio n/vnd.ms-excel"
>> objHttpContext. Response.AddHea der("Content-disposition",
>> "attachment;fil ename=export.xl s")
>> objHttpContext. Response.Charse t = ""
>>
>> "Hemant Sipahimalani" <Hemant Si**********@di scussions.micro soft.com>
>> wrote
>> in message news:C0******** *************** ***********@mic rosoft.com...
>> > The following piece of code is being used to export HTML to excel.
>> >
>> > HttpContext.Cur rent.Response.C ontentType =
>> > "applicatio n/vnd.ms-excel"
>> > HttpContext.Cur rent.Response.A ddHeader("conte nt-disposition",
>> > "attachment;fil ename=ABC.xls")
>> > HttpContext.Cur rent.Response.W rite(strHTML)
>> > HttpContext.Cur rent.Response.E nd()
>> >
>> > 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

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
6342
by: Hon Seng Phuah | last post by:
Hi all, I have a huge excel format file wants to export to sql server database. One of the field has combination of numeric and alphanumeric. When I import the excel format to sql server database, the numeric is successfully imported but the alphanumeric does not import at all. Does anyone know how to solve my problem?
2
447
by: zino | last post by:
I have a file that is created in Excel and saved as an htm file. (if I open the file through Excel it open as Excel file, if I click on the file name it open in internet explorer). I need to read this Excel/htm file but in excel mode through VB.net, in order to have acces to specifc cells and worksheets. how can I do that ? thanks
6
5902
by: Eric | last post by:
Dear All, I want to export datagrid content to a Excel file, the code just like below: Response.ContentType = "application/vnd.ms-excel" Response.Charset = "" Me.EnableViewState = False Dim tw As New System.IO.StringWriter() Dim hw As New System.Web.UI.HtmlTextWriter(tw) gridList.Columns(0).Visible = False
3
25045
by: sam | last post by:
Can you teach me how to export access file to excel file in VB.net? Thank in advance.
0
1640
by: Benny Ng | last post by:
Dear ALl, Now I want to export the crystal report to Excel file. But actually don't know how to export it with multiple sheet. Because sometime in some particular cases. It needs us to provided an Excel file with multi-sheet. But seems the crystal report haven't this function . SO , What can I do now? Any suggestion? Thanks,
0
2465
by: Srikash74 | last post by:
Hi, I am using File Upload Control in ASP.NET (2.0). I would like to know is there any way we can filter the file type and show only the required files (e.g .html) in the open dialog control (setting the Default file type ) when you click on the Browse button. Hope to hear from you soon. Thanks & Regards, Sreenivas Kaushik
9
5981
by: backups2007 | last post by:
please help. my code displays two errors that I'm having a hard time to resolve. here are the errors: first is: missing name in export statement; it generates an excel file. but this error still pops up for some reason. (I am able to generate an excel file when I directly put a query string.) second is:
0
2118
by: JFKJr | last post by:
Hello everyone! I am trying to export Access table data into Excel file in such a way that the table field names should be in the first line of each column in excel file followed by field data, and should start from column B in excel. The column A of the excel file should have heading "Extract Policy" followed by checkboxes so that the user can check which policy to extract after downloading the excel file. Can anyone suggest me how to do...
0
5343
by: vivek kapile | last post by:
Language: ASP.net Platform: Visual Studio 2008 with ASP.net Technology: Used in ASP.net Introduction 1. Add a gridview into a aspx file 2. Add a button into a aspx file and give the name as "btnExportToExcel" 3. Write a code in aspx.cs file
0
9892
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10658
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10718
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10347
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9497
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7889
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5730
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5915
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3171
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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

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