473,543 Members | 1,910 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(DataTabl e dt, HttpResponse response)
{
// clean up response object
response.Clear( );
response.Charse t = "";
response.Charse t = "UTF-8";
response.Conten tEncoding = System.Text.Enc oding.Default;

// set response object's mime type
response.Conten tType = "applicatio n/vnd.ms-excel";

System.IO.Strin gWriter sw = new System.IO.Strin gWriter();
System.Web.UI.H tmlTextWriter htw = new System.Web.UI.H tmlTextWriter(s w);

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.AlternatingI temStyle.BackCo lor = System.Drawing. Color.LightGray ;
dg.DataBind();
dg.RenderContro l(htw);

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

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

Similar topics

2
4864
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
2199
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. I am trying to write the contents of the file to the response but am having trouble. My code resides in the handler for a link-button's click event ...
6
5376
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 = dtLCPack.NewRow(); int intColCount = dtLCPack.Columns.Count; ArrayList arrlRow = (ArrayList)alLCPlist; <== Specified cast
0
249
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 without letting the user see this pop up. public static void Export(DataTable dt, HttpResponse response) { // clean up response object...
1
2027
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. Code: Dim oExcel As New Excel.Application() Dim oBooks As Excel.Workbooks Dim oBook As Excel.Workbook
5
5806
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
11137
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 with the help of methods SAVE AND SAVE AS. But it is displaying save dialog while it is saving. But since it is backend class i dont want that dialog. Is...
6
3351
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 a user without saving it to the disk first. Obviously saving the file first and streaming it afterwards is fairly easy to do, but it relies on...
0
1554
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 address and aspx pagename like 192.xxx.xxx.xx/exporttoexcell.aspx then popup page is not working. the popup page is being closed automatically , and export...
0
7411
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...
0
7354
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7594
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. ...
0
7693
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...
0
5888
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...
1
5282
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...
0
3394
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...
1
1824
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
978
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.