Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
hI,
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" };
            table.Columns.Add("Attributes");
            table.Columns.Add("Values");
            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 1:00am
Edited 31-Oct-11 1:02am
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Are you looking for something like this
 
http://tim.mackey.ie/HowtoExportADatasetToExcelCAspnet.aspx[^]
  Permalink  
Comments
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
http://stackoverflow.com/questions/373925/c-sharp-winforms-app-export-dataset-to-excel
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
good
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.
ef.SaveXls("DataSet.xls");
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 341
1 Marcin Kozub 225
2 Sergey Alexandrovich Kryukov 220
3 Praneet Nadkar 197
4 Shweta N Mishra 161
0 OriginalGriff 8,149
1 Sergey Alexandrovich Kryukov 7,287
2 DamithSL 5,614
3 Manas Bhardwaj 4,986
4 Maciej Los 4,910


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