473,406 Members | 2,220 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Export GridView to Excel does not open in Browser

Hi,
I have surfed through several posting about exporting gridview to excel and
it works great. using the following code...
response.Clear()
response.ContentType = "application/vnd.ms-excel"
response.Charset = ""
Dim stringWrite As New System.IO.StringWriter()
Dim htmlWrite As New System.Web.UI.HtmlTextWriter(stringWrite)

Dim dg As New GridView()

dg.GridLines = GridLines.None
dg.HeaderStyle.Font.Bold = True
dg.Datasource = myDataTable
dg.DataBind()
'tell the datagrid to render itself to our htmltextwriter
dg.RenderControl(htmlWrite)
'output the html
response.Write(stringWrite.ToString)
response.End()
However when response comes to the client it opens excel using Microsoft
Excel Application instead of inside the Browser. I have following questions...
1. How do I make it open inside the browser instead of using MS Excel
application?
2. Is there any way to explicitly instruct the browser to either open inside
browser or using MS Excel application?

Any sort of guidance on this is greatly appreciated.
Thanks
--Mike
Jun 13 '06 #1
2 2882
Response.AddHeader("Content-Disposition", "filename=""report.xls""")

if this does not work check out Response.ContentType and check the mime types.

the first line should work for you, although I have used it in conjunction
with Response.BinaryWrite.

Anyways goodluck ;)

"mike" wrote:
Hi,
I have surfed through several posting about exporting gridview to excel and
it works great. using the following code...
response.Clear()
response.ContentType = "application/vnd.ms-excel"
response.Charset = ""
Dim stringWrite As New System.IO.StringWriter()
Dim htmlWrite As New System.Web.UI.HtmlTextWriter(stringWrite)

Dim dg As New GridView()

dg.GridLines = GridLines.None
dg.HeaderStyle.Font.Bold = True
dg.Datasource = myDataTable
dg.DataBind()
'tell the datagrid to render itself to our htmltextwriter
dg.RenderControl(htmlWrite)
'output the html
response.Write(stringWrite.ToString)
response.End()
However when response comes to the client it opens excel using Microsoft
Excel Application instead of inside the Browser. I have following questions...
1. How do I make it open inside the browser instead of using MS Excel
application?
2. Is there any way to explicitly instruct the browser to either open inside
browser or using MS Excel application?

Any sort of guidance on this is greatly appreciated.
Thanks
--Mike

Jun 14 '06 #2
Hi Mach II,
I already tried that it does not work.
I remember somebody telling me sometime that it is client side setting that
makes a file either open in Browser or using a specific application. But
unfortunately I do not remember what exactly that is?
Thanks
--Mike
"MACH II" wrote:
Response.AddHeader("Content-Disposition", "filename=""report.xls""")

if this does not work check out Response.ContentType and check the mime types.

the first line should work for you, although I have used it in conjunction
with Response.BinaryWrite.

Anyways goodluck ;)

"mike" wrote:
Hi,
I have surfed through several posting about exporting gridview to excel and
it works great. using the following code...
response.Clear()
response.ContentType = "application/vnd.ms-excel"
response.Charset = ""
Dim stringWrite As New System.IO.StringWriter()
Dim htmlWrite As New System.Web.UI.HtmlTextWriter(stringWrite)

Dim dg As New GridView()

dg.GridLines = GridLines.None
dg.HeaderStyle.Font.Bold = True
dg.Datasource = myDataTable
dg.DataBind()
'tell the datagrid to render itself to our htmltextwriter
dg.RenderControl(htmlWrite)
'output the html
response.Write(stringWrite.ToString)
response.End()
However when response comes to the client it opens excel using Microsoft
Excel Application instead of inside the Browser. I have following questions...
1. How do I make it open inside the browser instead of using MS Excel
application?
2. Is there any way to explicitly instruct the browser to either open inside
browser or using MS Excel application?

Any sort of guidance on this is greatly appreciated.
Thanks
--Mike

Jun 15 '06 #3

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

Similar topics

9
by: | last post by:
I have a web page written in asp.net that has multiple datagrids on it that would need to be exported to Excel. Each of the datagrids would be a subset of what the datagrid above it was. Thus...
6
by: Paul Zanbaka | last post by:
I have this code below it works fine when exporting to excel. However 2 things: 1-It does prompt me to save to file to excel (just displays excel in browser) 2-It aonly works if...
7
by: mattmerc | last post by:
Hi all, We have all seen lot of method for exporting datagrids to Excel. I have a slightly different need. I think it should be easy to accomplish but I am not sure how. I would like when a user...
0
by: Peter | last post by:
I experienced a bug, "Control GridView1 of type GridView myst be placed inside a form tag with runat=server". But I did so. I do not why, please advise. my code as below. Thanks. Peter <%@...
3
by: =?Utf-8?B?bWFuaWthMDI=?= | last post by:
Hi, I have a GridView control in page called eventslisting which is inheriting from a MasterPage. The normal code to export to GridView does not work and gives me an error - "Control of type...
0
by: johnlim20088 | last post by:
Hi, Hi, currently I have a code below on my Listcontact.aspx file to export my gridview data to excel:- It is work success, and export the 'Contacts.xls' to my folder. But have following...
6
by: Sergio E. | last post by:
Hi, I'm looking for information about gridview's cell properties... I've the following case: one gridview with alternatirg row style and normalrowstyle, 3 o 4 custom styles that are applied to...
1
by: edwinparker | last post by:
Hi, I'm trying to convert a gridview to an excel report and have one small hang up. So far I've been able to create my gridview and export it to excel ok, but in my gridview I have an image. The...
0
by: hiranmaie | last post by:
Hi, I have a gridview with more than 10 rows of data. I want to export these gridview values into an excel sheet along with the header names of excel sheet. I am not using a database here. I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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,...
0
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...

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.