Creating an Excel Worksheet in C#.NET
I want to create an Excel worksheet with the details from a database and the important thing is the column names of the database should be displayed in the column headers of the excel sheet. for instance column names of an excel sheet is like this A B C D but for my program it must want to be displayed like UserName, Location, etc. please help me sir to get it done.

Sagar PardeshiRank #103 · 20.8K reputationPosted Jun 28, 2014, 5:42 AM EDT
http://csharp.net-informations.com/excel/csharp-excel-export.htm
Rahul PrasadRank #2,557 · 546 reputationPosted Jun 29, 2014, 7:55 PM EDT
refer this article - Export Data for database to Excel in C#
private void button1_Click(object sender, EventArgs e)
{
//connect database
OleDbConnection connection = new OleDbConnection();
connection.ConnectionString @"Provider=""Microsoft.Jet.OLEDB.4.0"";Data Source=""demo.mdb"";User Id=;Password="
OleDbCommand command = new OleDbCommand();
command.CommandText = "select * from parts";
DataSet dataSet = new System.Data.DataSet();
OleDbDataAdapter dataAdapter = new OleDbDataAdapter(command.CommandText,connection);
dataAdapter.Fill(dataSet);
DataTable t = dataSet.Tables[0];
//export datatable to excel
Workbook book = new Workbook();
Worksheet sheet = book.Worksheets[0];
sheet.InsertDataTable(t, true, 1, 1);
book.SaveToFile("insertTableToExcel.xls");
System.Diagnostics.Process.Start("insertTableToExcel.xls");
}
Arun Kumar Radhakrishnan19 reputationPosted Jun 29, 2014, 8:15 PM EDT
Arun Kumar Radhakrishnan19 reputationPosted Jun 29, 2014, 8:18 PM EDT
Rahul PrasadRank #2,557 · 546 reputationPosted Jun 29, 2014, 8:43 PM EDT
Sagar PardeshiRank #103 · 20.8K reputationPosted Jun 29, 2014, 9:46 PM EDT
http://www.codedigest.com/Articles/ASPNET/400_ImportUpload_Excel_Sheet_data_to_Sql_Server_in_C__and_AspNet.aspx
Darren Kang16 reputationPosted Jul 28, 2014, 1:24 AM EDT
In short, it uses this .NET library to process excel files and you call a direct API (InsertDataTable) on the required worksheet.
Also notice the InsertDataTableOptions.ColumnHeaders property will indicate if the columns names will be imported as a header row (first row).