473,394 Members | 1,971 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,394 software developers and data experts.

Exporting Datagrid's data to an Excel Sheet.

I have a web form in which I have a datagrid, I need to export this data to
a Microsoft Excel sheet.

I'm doing it thus:

Response.Clear();

Response.Buffer= true;

Response.ContentType = "application/vnd.ms-excel";

Response.Charset = "";

this.EnableViewState = false;

System.IO.StringWriter oStringWriter = new System.IO.StringWriter();

System.Web.UI.HtmlTextWriter oHtmlTextWriter = new
System.Web.UI.HtmlTextWriter(oStringWriter);

DataGrid1.RenderControl(oHtmlTextWriter);

Response.Write(oStringWriter.ToString());

Response.End();

But I'd like to avoid system ask user if desires open or save this file,
instead would open excel sheet as another window and when user saves the
file it be saved as an excel file.

Does somebody knows how achieve this?

I'll appreciate it very much.

A.L.

--
see07 - forum member
http://www.visual-basic-data-mining.net/forum
Nov 18 '05 #1
1 1439
This article provides a good example for you:
http://www.aspnetpro.com/NewsletterA...200309so_l.asp

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net
"http://www.visual-basic-data-mining.net/forum" <si******@gmail.com> wrote
in message news:ub**************@TK2MSFTNGP11.phx.gbl...
I have a web form in which I have a datagrid, I need to export this data to
a Microsoft Excel sheet.

I'm doing it thus:

Response.Clear();

Response.Buffer= true;

Response.ContentType = "application/vnd.ms-excel";

Response.Charset = "";

this.EnableViewState = false;

System.IO.StringWriter oStringWriter = new System.IO.StringWriter();

System.Web.UI.HtmlTextWriter oHtmlTextWriter = new
System.Web.UI.HtmlTextWriter(oStringWriter);

DataGrid1.RenderControl(oHtmlTextWriter);

Response.Write(oStringWriter.ToString());

Response.End();

But I'd like to avoid system ask user if desires open or save this file,
instead would open excel sheet as another window and when user saves the
file it be saved as an excel file.

Does somebody knows how achieve this?

I'll appreciate it very much.

A.L.

--
see07 - forum member
http://www.visual-basic-data-mining.net/forum

Nov 18 '05 #2

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

Similar topics

5
by: Anthony | last post by:
First time here so please bear with me. Set up a DTS package to export data to an excel sheet on an hourly basis. Problem is, it keeps appending to the same excel sheet. Any idea how to...
1
by: Matt | last post by:
I have code that generates a dataset and sends the results to the user and automatically opens Excel when the link is clicked. It works fine on my own machine and one server but I get the following...
4
by: Hitesh | last post by:
Hi, I have three datagrid control on my aspx page and one export to excel button, i want to export all the 3 datagrids contents in one excel file. how can i achive that? -- Thanks Hitesh
1
by: NancyA | last post by:
I am using the following code to write data from a datagrid to an Excel file: Dim tw As New System.IO.StringWriter Dim hw As New System.Web.UI.HtmlTextWriter(tw) dg.RenderControl(hw)...
2
by: TM | last post by:
I have an Excel sheet where I setup my needed formatting, page settings, ect, and would like to take my data from a datagrid and paste it into the excel file and print the excel file. Any idea...
3
by: | last post by:
Hello, I have a routine in my Windows application that exports the contents of a datagrid to Excel. It is modeled closely after the HowTo example on MSDN: http://tinyurl.com/5g2jm. Depending...
2
by: bienwell | last post by:
Hi, I have a question about exporting data from datagrid control into Excel file in ASP.NET. On my Web page, I have a linkbutton "Export data". This link will call a Sub Function to perform...
0
by: Sridhar | last post by:
Hi, I am having trouble renaming the excel sheet while exporting to excel. we have a datagrid that contains some analytical data. I have the name to the excel file as "temp.xls" inside the code....
7
by: leninv | last post by:
Hi, I have the following code where 'recs' is a record set. For i=0 to recs.Fields.Count - 1 if i = 0 then pindnt = string(itmlvl*2," ") response.write pindnt &...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
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...
0
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...

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.