Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

There is a quite good article including source code on accessing Excel from .net using VB.net.

 

http://support.microsoft.com/default.aspx?scid=kb;en-us;301982

 

Simply move through your dataset and write each value into your sheet.

Nonperformant solution: use two For each-Loops (one for the rows, one for the columns).

 

Don't know if it would work like that: take column from Dataset put it into column from Excel-sheet. Just try.

 

Voca

  • 6 years later...
Posted

Hi,

 

well if you are looking for easy, fast and clean solution, I recommend this Excel VB.NET component.

 

Here is a code snippet of DataSet to Excel export:

 

// 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");

Posted

The simplest solution I use is just to save it as a delimited text file (tab, comma, whatever), and then Excel can import it. In addition, it is not limited to Excel.

 

Todd

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...