473,405 Members | 2,187 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,405 software developers and data experts.

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 2723

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

Similar topics

6
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...
2
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...
2
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...
5
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
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
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...
10
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...
3
by: Shailesh Patel | last post by:
Hi, How do I export Html table to excel file? Thank you in advance. Shailesh
4
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...
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
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
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,...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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.