This is my Technical area of troubleshooting and learning new Programming skills and many more. Here you will find answers for many new technologies like asp.net 2.0/3.5,4.0 C# access, mysql, Amazon Webservice ,Sql-server, JD Edwards, SAS, Salesforce, APIs, MVC and many more. please visit & discuss.
Wednesday, March 27, 2019
Monday, March 11, 2019
Gridview Save as excel without dropping leading 0's (zeros) C# sap.net
protected void Button1_Click(object sender, EventArgs e)
{
Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=ForecastData.xls");
Response.Charset = "";
Response.Write("
");
Response.Write("ForecastData");
Response.Write("
");{
Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=ForecastData.xls");
Response.Charset = "";
Response.Write("
Response.Write("ForecastData");
Response.Write("
//Response.Write("Date:- " + DateTime.Today.ToShortDateString());
Response.Write("
");
// If you want the option to open the Excel file without saving then
// comment out the line below
//Response.Cache.SetCacheability(HttpCacheability.No Cache);
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new
HtmlTextWriter(stringWrite);
for (int i = 0; i < GridView1.Rows.Count; i++)
{
GridViewRow row = GridView1.Rows[i];
//Apply text style to each Row
row.Attributes.Add("class", "textmode");
}
GridView1.RenderControl(htmlWrite);
string style = @"";
Response.Write(style);
Response.ContentType = "application/text";
Response.Write(stringWrite.ToString());
Response.End();
}
code by Neha
Subscribe to:
Posts (Atom)