Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename= Barcodes_Detail.xls");
Response.Charset = "";
Response.ContentType = "application/vnd.xls";
StringWriter StringWriter = new System.IO.StringWriter();
HtmlTextWriter HtmlTextWriter = new HtmlTextWriter(StringWriter);
DataGrid datagrid = new DataGrid();
datagrid.DataSource = m_details;
datagrid.DataBind();
datagrid.HeaderStyle.Font.Bold = true;
datagrid.AllowPaging = false;
// Code for making all columns data text in excel. Otherwise numeric data : text-align: right.
// We need this code when a column have text as well as numeric data.. to resolve alignment issue we have to use below bold 5 lines
foreach (DataGridItem item in datagrid.Items)
{
for (int i = 0; i < item.Cells.Count; i++) // loop through all the cells in grid
item.Cells[i].Attributes.Add("style", "mso-number-format:\\@");
}
datagrid.RenderControl(HtmlTextWriter);
// string headerTable = @"<div style='width:100%;text-align:center; font-size :16px; font-weight :bold;'>" + search_text.Text + " </div>";
string headerTable = @"<div style='width:100%;text-align:center; font-size :16px; font-weight :bold;'>" + search_text.Text + "</div>";
Response.Write(headerTable);
Response.Write(StringWriter.ToString());
Response.Flush();
Response.End();
Response.AddHeader("content-disposition", "attachment;filename= Barcodes_Detail.xls");
Response.Charset = "";
Response.ContentType = "application/vnd.xls";
StringWriter StringWriter = new System.IO.StringWriter();
HtmlTextWriter HtmlTextWriter = new HtmlTextWriter(StringWriter);
DataGrid datagrid = new DataGrid();
datagrid.DataSource = m_details;
datagrid.DataBind();
datagrid.HeaderStyle.Font.Bold = true;
datagrid.AllowPaging = false;
// Code for making all columns data text in excel. Otherwise numeric data : text-align: right.
// We need this code when a column have text as well as numeric data.. to resolve alignment issue we have to use below bold 5 lines
foreach (DataGridItem item in datagrid.Items)
{
for (int i = 0; i < item.Cells.Count; i++) // loop through all the cells in grid
item.Cells[i].Attributes.Add("style", "mso-number-format:\\@");
}
datagrid.RenderControl(HtmlTextWriter);
// string headerTable = @"<div style='width:100%;text-align:center; font-size :16px; font-weight :bold;'>" + search_text.Text + " </div>";
string headerTable = @"<div style='width:100%;text-align:center; font-size :16px; font-weight :bold;'>" + search_text.Text + "</div>";
Response.Write(headerTable);
Response.Write(StringWriter.ToString());
Response.Flush();
Response.End();
No comments:
Post a Comment