Solved

Dataset to Excel

Posted on 2013-05-14
4
377 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 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

820 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