Exoprt Data Grind to excel
Exoprt Data Grind to excel in .NET 3.5 C#?
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Ahmed JSPosted Nov 9, 2014, 10:06 AM
below link you can get
http://sqlneed.blogspot.com/2014/03/how-to-export-datagridview-to-excel.html
Jacke ElisPosted Jan 30, 2015, 6:18 AM
Also here is an article about how you can import or export a DataGridView control to excel.
Joginder BangerPosted Nov 9, 2014, 11:45 PM
private void ExportDataSetToExcel(DataTable table, string fileName)
{
//Creae an Excel application instance
excel.Application excelApp = new excel.Application();
//Create an Excel workbook instance and open it from the predefined location
excel.Workbook excelWorkBook = excelApp.Workbooks.Open(fileName);
excelApp.DisplayAlerts = false;
foreach (excel._Worksheet sheet in excelWorkBook.Sheets)
{
if (sheet.Name.ToLower() != "testing")
{
sheet.Delete();
excelWorkBook.Save();
}
}
excelApp.DisplayAlerts = true;
excel.Worksheet excelWorkSheet = (excel.Worksheet)(excelWorkBook.Sheets.Add());
for (int i = 1; i < table.Columns.Count + 1; i++)
{
excelWorkSheet.Cells[1, i] = table.Columns[i - 1].ColumnName;
}
for (int j = 0; j < table.Rows.Count; j++)
{
for (int k = 0; k < table.Columns.Count; k++)
{
excelWorkSheet.Cells[j + 2, k + 1] = table.Rows[j].ItemArray[k].ToString();
}
}
excelWorkBook.Save();
excelWorkBook.Close();
excelApp.Quit();
Response.Clear();
Response.AddHeader("Content-Disposition", "attachment; filename=" + "Product" + ".xls");
Response.AddHeader("Content-Length", fileName);
Response.ContentType = "application/octet-stream";
Response.WriteFile(fileName);
Response.End();
}
//Button Export TO Excel
protected void ExportToExcel(object sender, EventArgs e)
{
productexport = objproduct.importProductData();
productexport.Columns.Add(col);
col.SetOrdinal(0);
for (int i = 0; i < productexport.Rows.Count; i++)
{
productexport.Rows[i]["SrNo"] = i + 1;
}
string temp = Server.MapPath("Export/Product_Export.xls");
var fpath = temp;
if (fpath.Trim() != string.Empty)
ExportDataSetToExcel(productexport, fpath);
}
Abhay ShankerPosted Oct 18, 2014, 3:15 AM
http://csharp.net-informations.com/excel/csharp-excel-datagridview.htm