473,541 Members | 15,105 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Html / Aspx Export to Excel

for exporting to excel just call the function below in sample code and pass
the page object from an aspx and the aspx page contents are rendered in
excel..

make control.visible = false if you dont want those controls to be exported
to excel.

the same function can be overloaded to pass say a datagrid (in most search
screens we need results only)also.

// For Direct Exporting From HTML to excel
// Call this function on Button Click
public static void HtmlExportToExcel(Page PageObject)

{

HttpContext.Current.Response.Buffer = true;
HttpContext.Current.Response.Clear();

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

HttpContext.Current.Response.ContentEncoding =
System.Text.Encoding.Default;
HttpContext.Current.Response.AddHeader("content-disposition",
"attachment; filename=RMCExport-" +
System.DateTime.Now.ToString("MMMddyyyy-hhmmtt") + ".xls");
HttpContext.Current.Response.Charset = string.Empty ;

PageObject.EnableViewState = false;

StringWriter tw = new StringWriter();

HtmlTextWriter hw = new HtmlTextWriter(tw);

//DataGrid dg = new DataGrid();

//dg.DataSource = SourceDataTable;

//dg.DataBind();
PageObject.RenderControl (hw);
//dgrSearchResults.RenderControl(hw);

HttpContext.Current.Response.Write(tw.ToString());

HttpContext.Current.Response.Flush() ;

HttpContext.Current.Response.Close();
}
--
Y2KPRABU, MCP, INDIA
WEB APPS
Sep 27 '06 #1
0 2735

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

Similar topics

6
5757
by: A P | last post by:
Is this possible? I am planning to export data from SQL that generates HTML table. Instead of selecting the table and then copy then paste to word, I need a script(JS or VB) that will automatically export or open the Query to word.
2
10012
by: bill | last post by:
Hi All, When I send html content with Excel MIME type, the page break style sheet {page-break-before: always} doesn't work at Excel spreadsheet. Any idea to convert html page break style sheet to Excel page break? Thanks in advance
2
2422
by: Slipperman | last post by:
i'm a relative newbie to javascript and the more advanced techniques of Web dev't so bear with me. what i'd like to accomplish is twofold.. 1. in client-side JS in an aspx file, i'd like to POST straight html via the Request object down to an asp page that runs server-side script. 2. i want this server-side script to retrieve the html from the...
5
3748
by: Maria L. | last post by:
Hi, I need to export the content of a DataGrid (in Windows application in C#), into an Excel spreadsheet. Anyone knows how to do this? Any code snippets would help! thanks a lot, Maria
5
31895
by: Simon | last post by:
Dear reader, With the export command you can export a query to Excel. By activate this command a form pop's up with the following text:
5
4162
by: =?Utf-8?B?c2NobWlkdGU=?= | last post by:
Hi How can I Export an HTML Table to excel? My goal is a button, and when the user clicks this button a popup appears asking the user to 'open' or 'save' the generated Excel file. Actually I'm exporting by rendering my table to an htmlwriter and sending this to excel. This is working nearly perfect. There's a problem with Excel's...
10
3880
by: bill | last post by:
I have been searching everywhere AND am a bit new to vb .net/aspx, but can't seem to find anything that works. Specifically, I need to export a dataset from a webapp written in vb .net to a new excel spreadsheet with multiple tabs (each tab would contain different rows from the dataset). Does anyone have any sample code or examples I might...
3
8051
by: Shailesh Patel | last post by:
Hi, How do I export Html table to excel file? Thank you in advance. Shailesh
4
1376
by: =?Utf-8?B?VGVycnk=?= | last post by:
Hello, I'm having issues with writing html string to a bookmark in MS Word 2007. I have a richtextbox control which returns HTML string, I would like to take that string and put it into a MS Word document and formatted to HTML Tags. Is this possible? And if so, can you point me in the right direction. Thank you, Terry
0
7373
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
7553
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
7712
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...
0
5849
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...
0
4870
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...
0
3372
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...
0
3367
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1784
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
0
606
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...

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.