#region " EXPORT TO EXCEL "
public void ExportToExcel(DataSet ds)
{
try
{
Response.Clear();
Response.Buffer = true;
Response.AddHeader("content-disposition", "attachment; filename=" + HdnMnth.Value + "/2011_Report.doc");
Response.ContentType = "application/vnd.ms-excel";
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
GridView gvReport = null;
TableCell cell1 = null;
Table tb = new Table();
TableRow tr1 = null;
tr1 = new TableRow();
cell1 = new TableCell();
cell1.ColumnSpan = ds.Tables.Count + (ds.Tables.Count / 2);
cell1.Style.Add("color", "Blue");
cell1.Style.Add("font-weight", "Bold");
cell1.Text = HdnMnth.Value + "/2011 Montly Report";
tr1.Cells.Add(cell1);
tb.Rows.Add(tr1);
tr1 = new TableRow();
for (int i = 0; i < ds.Tables.Count; i++)
{
gvReport = new GridView();
gvReport.AllowPaging = false;
gvReport.DataSource = ds.Tables[i];
gvReport.DataBind();
cell1 = new TableCell();
cell1.Style.Add("width", "250px");
cell1.Controls.Add(gvReport);
tr1.Cells.Add(cell1);
cell1 = new TableCell();
cell1.Text = " ";
tr1.Cells.Add(cell1);
}
tb.Rows.Add(tr1);
tb.RenderControl(htw);
Response.Output.Write(sw.ToString());
Response.Flush();
Response.End();
}
catch (Exception ex)
{
}
}
#endregion