protected void ExportToExcelImageWithOtherColumn() { Response.Clear(); Response.Buffer = true; Response.AddHeader("content-disposition", "attachment;filename=GridViewExport.xls"); Response.Charset = ""; Response.ContentType = "application/vnd.ms-excel"; using (StringWriter sw = new StringWriter()) { HtmlTextWriter hw = new HtmlTextWriter(sw);
//To Export all pages. grdAwardShow.AllowPaging = false; string varPlant = ddlPlant.SelectedItem.ToString(); this.BindGrid(varPlant, "");
grdAwardShow.HeaderRow.BackColor = Color.White; foreach (TableCell cell in grdAwardShow.HeaderRow.Cells) { cell.BackColor = grdAwardShow.HeaderStyle.BackColor; } foreach (GridViewRow row in grdAwardShow.Rows) { row.BackColor = Color.White; foreach (TableCell cell in row.Cells) { if (row.RowIndex % 2 == 0) { cell.BackColor = grdAwardShow.AlternatingRowStyle.BackColor; } else { cell.BackColor = grdAwardShow.RowStyle.BackColor; } cell.CssClass = "textmode"; } }
grdAwardShow.RenderControl(hw);
//Style to format numbers to string. string style = @"<style> .textmode { } </style>"; Response.Write(style); Response.Output.Write(sw.ToString()); Response.Flush(); Response.End(); } }