Solved

Dataset to Excel

Posted on 2013-05-14
4
375 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
  • 2
4 Comments
 
LVL 69

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

914 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now