I'm using the ExcelPackage library which uses the OpenXML standard file format from Office 2007 and makes it really easy to create your own Excel sheets fro your C# or VB.NET app with little effort.
WORD OF WARNING: it has come to my attention (I didn't pay enough attention to that fact) that the ExcelPackage
on CodePlex is actually licensed under a rather strict GPL license, which makes it virtually unusable for anyone but hobbyists. If you use it, you'll have to reveal all your source code of stuff produced with it.
It might look something like this:
using OfficeOpenXml; // namespace for the ExcelPackage assembly
FileInfo newFile = new FileInfo(@"C:\mynewfile.xlsx");
using (ExcelPackage xlPackage = new ExcelPackage(newFile))
{
ExcelWorksheet worksheet = xlPackage.Workbook.Worksheets.Add("Tinned Goods");
// write some titles into column 1
worksheet.Cell(1, 1).Value = "Product";
worksheet.Cell(4, 1).Value = "Peas";
worksheet.Cell(5, 1).Value = "Total";
// write some values into column 2
worksheet.Cell(1, 2).Value = "Tins Sold";
ExcelCell cell = worksheet.Cell(2, 2);
cell.Value = "15"; // tins of Beans sold
string calcStartAddress = cell.CellAddress; // we want this for the formula
worksheet.Cell(3, 2).Value = "32"; // tins Carrots sold
worksheet.Cell(5, 2).Formula = string.Format("SUM({0}:{1})",
calcStartAddress, calcEndAddress);
}
Totally free, available with source, doesn't require an installation of Office on the machine it runs on (e.g. your web server), no slow and messy COM interop - it just works like a charm! Very highly recommended.
Marc