This is my technical area for troubleshooting and learning new programming skills and much more. Here, you will find answers on a wide range of technologies such as AI, Machine Learning, OpenAI, Databricks, ASP.NET, C#, Python, Microsoft Access, MySQL, Amazon Web Services, SQL Server, PL/SQL, JD Edwards, SAS, Salesforce, APIs, MVC, and many others. Please feel free to visit and join the discussion!
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)