473,804 Members | 2,271 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Conten tType = "applicatio n/vnd.ms-excel"
response.Charse t = ""
Dim stringWrite As New System.IO.Strin gWriter()
Dim htmlWrite As New System.Web.UI.H tmlTextWriter(s tringWrite)

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.RenderContro l(htmlWrite)
'output the html
response.Write( stringWrite.ToS tring)
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 2900
Response.AddHea der("Content-Disposition", "filename=""rep ort.xls""")

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

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

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.Conten tType = "applicatio n/vnd.ms-excel"
response.Charse t = ""
Dim stringWrite As New System.IO.Strin gWriter()
Dim htmlWrite As New System.Web.UI.H tmlTextWriter(s tringWrite)

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.RenderContro l(htmlWrite)
'output the html
response.Write( stringWrite.ToS tring)
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.AddHea der("Content-Disposition", "filename=""rep ort.xls""")

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

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

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.Conten tType = "applicatio n/vnd.ms-excel"
response.Charse t = ""
Dim stringWrite As New System.IO.Strin gWriter()
Dim htmlWrite As New System.Web.UI.H tmlTextWriter(s tringWrite)

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.RenderContro l(htmlWrite)
'output the html
response.Write( stringWrite.ToS tring)
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
3015
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 far, I've had no luck in finding anything to work reliably. Some of the files I've saved (using a radio button click event), will open fine in Excel, others give me an "Unable to open file" message. Any help appreciated.
6
671
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 AllowSorting="false' in <asp:GridView > tag Can anyone help! -- Paul
7
4917
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 clicks a button for exporting a datagrid, that the excel file is saved on the server and that it DOES NOT prompt the user to open or save. Here is the code I am using for standard export that prompts the user. Thanks all. Dim...
0
1251
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 <%@ Page language="C#" %> <script runat="server"> protected void Page_Load(object sender, EventArgs e) {
3
10129
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 GridView must be placed inside form tag with runat = server". I understand that this is because my Masterpage has the formtag and not the eventslisting page. As a workaround I programatically created an HTML form, added runat=server attribute to it...
0
1697
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 problem-> 1) when i open with wordpad, it show html tag with the value. 2) when i open with excel, it look ok, BUT i don't want the colour and button to be export.
6
6492
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 cells in the row_databound event, and now I nedd to do a excel export of the gridview exactly as is showed in the browser, but al the examples and thigs I've tried don't send the cell color to excel and now I think if I can read the gridview...
1
3364
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 problem is, the image won't display unless I'm connected to the Internet or if I use a relative path and have the image stored relative to the excel file. Is it possible to "embed" the image from the gridview into the excel workbook so I could give...
0
1927
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 need to open an excel application at the click of a button and save the gridview values into the excel sheet opened. Please help me out to solve this problem. Thanks & Regards,
0
10599
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10346
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
10347
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
9173
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
7635
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
6863
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5531
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
5673
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3001
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.