Export to Excel in .Net

There is a wonderful open source Excel Library through which you can easily convert DataSet into multi sheet excel file, just by one line of code like this:-

ExcelXmlWorkbook sheet = ExcelXmlWorkbook.DataSetToWorkbook(sourceDataSet);

Also adding a sample code which will really help you to create reports:-

 
private void YougeshSample()
{
    DataTable dt = CreateDataTable();
 
    ExcelXmlWorkbook book = new ExcelXmlWorkbook();
    book.Properties.Author = "Zeeshan Umar";
    book.Properties.Company = "Sample Company";
    book.Properties.Title = "Sample Title";
    book.Properties.Subject = "Subject";
 
    Worksheet ws = book[0];
    ws.Name = "Sample Sheet Name"; //Sheet Name
    ws.Font.Name = "Calibri";//Setting font for all sheet
    ws.Font.Size = 11;
 
    int rowIndex = 0;
    Row row;
    row = ws[rowIndex++];
 
    int colIndex = 0;
    foreach (DataColumn dc in dt.Columns) //Creating Headings
    {
        row[colIndex].Value = "Heading " + dc.ColumnName;
        row[colIndex].Border.Sides = BorderSides.All;
        row[colIndex].Style.Interior.Color = Color.LightGray;
        colIndex++;
    }
 
    foreach (DataRow dr in dt.Rows) // Adding Data into rows
    {
        colIndex = 0;
        row = ws[rowIndex++];
        foreach (DataColumn dc in dt.Columns)
        {
            row[colIndex].Value = Convert.ToInt32(dr[dc.ColumnName]);
            row[colIndex].Border.Sides = BorderSides.Left | BorderSides.Right;
            setIntegerFormat(row[colIndex]);
            colIndex++;
        }
    }
 
    row = ws[rowIndex++];
    colIndex = 0;
    foreach (DataColumn dc in dt.Columns) //Adding summ formula for last row
    {
        row[colIndex].Value = FormulaHelper.Formula("sum", 
            new Range(ws[colIndex, 1], ws[colIndex, 9]));
        row[colIndex].Border.Sides = BorderSides.All;
        row[colIndex].Style.Interior.Color = Color.LightGray;
        colIndex++;
    }
 
    string s = "c:\\" + Guid.NewGuid().ToString() + ".xml";
    book.Export(s);
}
 
private static DataTable CreateDataTable()
{
    DataTable dt = new DataTable();
    for (int i = 0; i < 300; i++)
    {
        dt.Columns.Add(i.ToString());
    }
    for (int i = 0; i < 10; i++)
    {
        DataRow dr = dt.NewRow();
        foreach (DataColumn dc in dt.Columns)
        {
 
            dr[dc.ToString()] = i;
        }
        dt.Rows.Add(dr);
    }
    return dt;
}
 
private void setIntegerFormat(Cell cell)
{
    cell.DisplayFormat = DisplayFormatType.Custom;
    cell.CustomFormatString = "#,##0";
}
 
private void setDateFormat(Cell cell)
{
    cell.DisplayFormat = DisplayFormatType.GeneralDate;
    cell.CustomFormatString = "dd\\-mmm\\-yyyy\\ hh:mm";
}

For further details see this link:-
A Very Easy to Use Excel XML Import-Export Library

To download latest version of library see this link:-
Excel Xml Library 2.45 released