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

saving datatable to excel without popup

I'm using the following class to save data from database to an excel sheet. I
wonder how to do so without a popup box showing up (open, save)?Thanks
I want to save the exel sheet on the hard drive without letting the user see
this pop up.

public static void Export(DataTable dt, HttpResponse response)
{
// clean up response object
response.Clear();
response.Charset = "";
response.Charset = "UTF-8";
response.ContentEncoding = System.Text.Encoding.Default;

// set response object's mime type
response.ContentType = "application/vnd.ms-excel";

System.IO.StringWriter sw = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htw = new System.Web.UI.HtmlTextWriter(sw);

DataGrid dg = new DataGrid();
dg.AllowPaging = false;
dg.AllowSorting = false;
dg.DataSource = dt;
dg.ShowHeader = true;
dg.HeaderStyle.BackColor = System.Drawing.Color.DarkGray;
dg.HeaderStyle.ForeColor = System.Drawing.Color.White;
dg.HeaderStyle.Font.Bold = true;
dg.AlternatingItemStyle.BackColor = System.Drawing.Color.LightGray;
dg.DataBind();
dg.RenderControl(htw);

response.Write(WriteHeader());
response.Write(sw.ToString());
response.Write(WriteFooter());
response.End();
}
Jul 25 '05 #1
0 3231

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

Similar topics

2
by: Andreas Klemt | last post by:
Hello, which is the best way to transfer my DataTable to a PopUp Window? Using Context would be great but I it seems not to work. Which is the best solution? Thanks in advance, Andreas
10
by: KeithRaginF | last post by:
Hello I am trying to return the contents of an Excel file. However, I don't want to just redirect the request to the Excel file since it does not reside in a location where that is appropriate. ...
6
by: gane kol | last post by:
Hi, I have a code that creates a datatable from an arraylist, but i am getting an error in casting in for (int intRow = 0; intRow < alLCPlist.Count; intRow++) { DataRow drow =...
0
by: viktor9990 | last post by:
I'm using the following class to save data from database to an excel sheet. I wonder how to do so without a popup box showing up (open, save)?Thanks I want to save the exel sheet on the hard drive...
1
by: Mark | last post by:
Hello - I'm opening/saving an Excel workbook from ASP.Net. When I try to save the workbook I get the error: System.Runtime.InteropServices.COMException: The remote procedure call failed. ...
5
by: Mark | last post by:
Hi - I've a data table that I want to save to an external Access database. I'm interested in sample code that would perform this save. Thanks, Mark (VB.NET, .Net framework 1.0)
7
by: alwayssmiling | last post by:
Hi frends, In my application, a class supports backend processing. In this class im creating a new excel sheet and im inserting some data into this excel sheet, and im trying to save the file...
6
by: Karl | last post by:
Hi all, It may seem like a rather odd request (or not) but I would like to be able to create a file (doc, jpg, xls or one of many other files that can be automated) on a website and stream it to...
0
by: mustaqueahmad | last post by:
Hi All, I am getting export to excel problem when I am giving IPAddress in URL, but it is working correct when am giving localhost and page name. eg : when I am writing My machine IP...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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:
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
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...

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.