This is Mariyappan.I want export to Excel in asp.net v3.5.My problem is export textbox vale.
<%@ Page Language="C#" AutoEventWireup="true" EnableEventValidation="false" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %>
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Pero15 reputationPosted Jun 2, 2010, 1:45 AM EDT
you can try this Excel .NET library.
Here is a code snippet how to export DataGrid to Excel in Excel ASP.NET application:
// Get DataTable that DataGrid is bound to.
var dataTable = (DataTable)dataGrid.DataSource;
// Create new ExcelFile.
var ef = new ExcelFile();
// Add new worksheet to the file.
var ws = ef.Worksheets.Add(dataTable.TableName);
// Insert the data from DataTable to the worksheet starting at cell "A1".
ws.InsertDataTable(dataTable, "A1", true);
// Stream file to browser.
Response.Clear();
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("Content-Disposition", "attachment; filename=Employee.xls");
ef.SaveXls(Response.OutputStream);
Response.End();
Ritesh Diyawar101 reputationPosted Jun 2, 2010, 2:31 AM EDT
hi Mariyappan...
this code may be usefule for u------------------------------------------------------------------code start-----------------------------------------
HtmlForm htmlfrom = new HtmlForm();
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
tbl.Parent.Controls.Add(htmlfrom);
htmlfrom.Controls.Add(tbl);
htmlWrite.BeginRender();
htmlfrom.RenderControl(htmlWrite);
htmlWrite.BeginRender();
Response.Clear();
Response.Buffer = true;
Response.ContentType = "application/vnd.ms-excel";
Response.Charset = "";
Response.AppendHeader("Content-Disposition", "attachment; filename=" + name + ".xls");
Response.Write(stringWrite.ToString());
Response.End();
------------------------------------------------------------------code end-----------------------------------------
Ritesh Diyawar