ExcelPackage package = new ExcelPackage(); ExcelWorksheet gridview1= package.Workbook.Worksheets.Add("gridview 1"); ExcelWorksheet gridview2= package.Workbook.Worksheets.Add("gridview 2"); DataTable gridview1= new DataTable(); for (int i = 0; i < gridview_1.Columns.Count; i++) { gridview1.Columns.Add("column" + i.ToString()); } foreach (GridViewRow row in gridview_1.Rows) { DataRow dr = gridview1.NewRow(); for (int j = 0; j < gridview_1.Columns.Count; j++) { row.Cells[j].Text = row.Cells[j].Text.Replace(" ", " "); dr["column" + j.ToString()] = row.Cells[j].Text; } gridview1.Rows.Add(dr); } gridview1.Cells["A1"].LoadFromDataTable(gridview1, true); DataTable gridview2= new DataTable(); for (int i = 0; i < gridview_2.Columns.Count; i++) { gridview2.Columns.Add("column" + i.ToString()); } foreach (GridViewRow row in gridview_1.Rows) { DataRow dr = gridview2.NewRow(); for (int j = 0; j < gridview_2.Columns.Count; j++) { row.Cells[j].Text = row.Cells[j].Text.Replace(" ", " "); dr["column" + j.ToString()] = row.Cells[j].Text; } gridview2.Rows.Add(dr); } gridview2.Cells["A1"].LoadFromDataTable(gridview2, true); Response.Clear(); package.SaveAs(Response.OutputStream); Response.AddHeader("content-disposition", "attachment; filename=" + filename + ";"); Response.Charset = ""; Response.ContentType = "application/vnd.xlsx"; Response.End();
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)