Here goes one more needy component for developers. a lot of developers always had a problem of exporting data to excel programmatically. if you Google this topic you will get many results regarding this. here are some which caught my eyes.
- How To Use ADO.NET to Retrieve and Modify Records in an Excel Workbook With Visual Basic .NET
- DataSet to Excel in Two steps – with Different Styles- by Krishna_accent
- And finally comes our good old CSV files.
the first one seems to be ok. but have little more work to be done on coding. the second is a really good one, but again we need excel to be installed, which again run out of our needs.
using CSV is ok for unformatted Comma Separated Values.
But Recently I found Carlos Aguilar Mares has this wonderful FREE component called ExcelXmlWriter , to export data to excel. it doesn’t need excel to be installed and it can be used to generate formatted excel workbooks with very few lines of code.
1: using CarlosAg.ExcelXmlWriter;
2:
3: class TestApp {
4: static void Main(string[] args) {
5: Workbook book = new Workbook();
6: Worksheet sheet = book.Worksheets.Add(“Sample”);
7: WorksheetRow row = sheet.Table.Rows.Add();
8: row.Cells.Add(“Hello World”);
9: book.Save(@”c:\test.xls”);
10: }
11: }
the download has a very easy to understand help file explaining how to use this. you can download it in his website here.
Clean and simple isn’t it ?



September 26th, 2008 at 7:33 pm
This was wonderful help! Thanks! I was looking for a way to export a DataGridView’s data to Excel without needing to use the com objects, as that can be very messy. This was a lifesaver.
October 14th, 2008 at 2:48 am
try opening that in open office. and you’ll see xml structured file. I see this as a vunerability. since you can read it as plain text. I wish there’s a way to convert it to binary format. since this is a great tool.