Click here to Skip to main content
13,051,404 members (48,377 online)
Rate this:
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 :( Please help me out with this. Thanks!
Posted 31-Oct-11 0:00am
Updated 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 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 31-Oct-11 7:30am
Refer this thread too
bizzare1988 2-Nov-11 0:07am
works perfectly, the link you sent! thanks a lot :) i mean, the second link, for verification.
Anuja Pawar Indore 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
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170713.1 | Last Updated 31 Oct 2011
Copyright © CodeProject, 1999-2017
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