Click here to Skip to main content
11,635,142 members (67,169 online)
Rate this: bad
Please Sign up or sign in to vote.
I have a table as shown:

 DataSet ds = new DataSet();
            System.Data.DataTable table = new System.Data.DataTable();
            table = ds.Tables.Add();
            string[] s1 = { "name", "age" };
            string[] s2 = { "John", "30" };
            for (int i = 0; i < 2; ++i)
                table.Rows.Add(s1[i], s2[i]);

I need to put the values of Attributes and Values into an excel sheet. I've been trying many methods, but only to get errors Frown | :( Please help me out with this. Thanks!
Posted 31-Oct-11 0:00am
Edited 31-Oct-11 0:02am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Are you looking for something like this[^]
bizzare1988 at 31-Oct-11 6:18am
Hi Anuja,My application is not a web application. will it work then? When i do this, i get an error: Object reference not set to an instance of an object.
On checking,The response value is null. What can i do?
Anuja Pawar Indore at 31-Oct-11 7:30am
Refer this thread too
bizzare1988 at 2-Nov-11 0:07am
works perfectly, the link you sent! thanks a lot :) i mean, the second link, for verification.
Anuja Pawar Indore at 2-Nov-11 2:10am
WC :)
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

try this
// Create new ExcelFile.
var ef = new ExcelFile();
// Imports all the tables from DataSet to new file.
foreach (DataTable dataTable in dataSet.Tables)
    // Add new worksheet to the file.
    var ws = ef.Worksheets.Add(dataTable.TableName);
    // Insert the data from DataTable to the worksheet starting at cell "A1".
    ws.InsertDataTable(dataTable, "A1", true);
// Save the file to XLS format.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 8,736
1 Sergey Alexandrovich Kryukov 8,419
2 Mika Wendelius 6,845
3 F-ES Sitecore 2,354
4 Suvendu Shekhar Giri 2,205

Advertise | Privacy | Mobile
Web01 | 2.8.150728.1 | Last Updated 31 Oct 2011
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100