Wednesday, May 19, 2010
Dataset to excel multiple worksheets using .Net
The aim of this Article is provide a native .NET solution to dataset to excel multiple worksheets without using COM interop or OLEDB connection
You can use a library called ExcelLibrary. It's a free, open source library posted on Google Code:
ExcelLibrary
Here is sample Code:
DataSet ds = new DataSet();
DataTable dt1 = new DataTable("Table 1");
dt1.Columns.Add("Column A", typeof(String));
dt1.Columns.Add("Column B", typeof(String));
dt1.Rows.Add("Test 1", "Test 2");
dt1.Rows.Add("Test 3", "Test 4");
ds.Tables.Add(dt1);
DataTable dt2 = new DataTable("Table 2");
dt2.Columns.Add("Column C", typeof(String));
dt2.Columns.Add("Column D", typeof(String));
dt2.Rows.Add("Test 5", "Test 6");
dt2.Rows.Add("Test 7", "Test 8");
ds.Tables.Add(dt2);
DataTable dt3 = new DataTable("Table 3");
dt3.Columns.Add("Column E", typeof(String));
dt3.Columns.Add("Column F", typeof(String));
dt3.Rows.Add("Test 9", "Test 10");
dt3.Rows.Add("Test 11", "Test 12");
ds.Tables.Add(dt3);
DataSetHelper.CreateWorkbook("D:\\ExcelMultipleSheets\\ExcelMultipleSheets_Test.xls", ds);
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment