Solved

Dataset to Excel

Posted on 2013-05-14
4
378 Views
Last Modified: 2013-05-15
I want to write an Excel file with a dataset . How can this be done?
0
Comment
Question by:VBdotnet2005
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 39165638
0
 
LVL 5

Expert Comment

by:JHalliday
ID: 39165654
I'm making some assumptions here as your question is a little vague but I'm assuming you have knowledge of Visual Basic and understand the concept of "for each" looping.

The easiest way to do what you need is to write the data set to a CSV file that can be opened in Excel. Therefore you will need to do the following (this is in pseudo code)

Create dataset
Declare an empty string called strOutput
Open a new empty file four output and put it in Append mode

For each row in dataset

   For each column in the row
      Read each field and add to a strOutput + ","
   Loop each column

   Write strOutput to the output file[/indent]
Loop each row

close the file
empty the dataset

Open in new window

Hope this makes sense

Regards

Jon
0
 

Author Comment

by:VBdotnet2005
ID: 39165731
I found this object. It works pretty good. I have datatable and I want to save it to Excel file. Now, I want to get rid of header name. It displays "column1, column2, etc".
http://closedxml.codeplex.com/
0
 
LVL 5

Accepted Solution

by:
JHalliday earned 500 total points
ID: 39165774
Set the name property of each of your data table columns to what you want otherwise there isn't a way to do this as your treating the data as a DataTable in Excel and you have to have column names in the Excel DataTable.

If you save it as a CSV it can still be opened in Excel and doesn't require column names.
0

Featured Post

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

732 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question