473,327 Members | 2,090 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,327 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 3229

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: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.