Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Dataset export to Excel (Win App - NOT ASP.NET!)

Posted on 2004-03-24
13
Medium Priority
?
1,265 Views
Last Modified: 2012-06-27
Hi,

Sorry for the NOT ASP.NET but everywhere I look online I cannot find what code I want but just stuff for ASP.NET.

I have a dataset that I load from a SQL dB into a datagrid. I want to export this dataset to excel.

It's that simple - everyone else can do this ite seems but me.

Thanks.
0
Comment
Question by:farawayman
[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
  • 5
  • 5
  • 2
  • +1
13 Comments
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 10666190
0
 
LVL 27

Expert Comment

by:Dabas
ID: 10666567
Hi farawayman:
Alternatively, use the dataset's WriteXML method to save your data to an xml file.
Then open the xml file in Excel. Excel will read it OK
You can then save as xls, or write a program that does the reading from xml and saveas xls for you.

Dabas
0
 

Author Comment

by:farawayman
ID: 10666577
Thanks - but I have already been there and posted this questions as I specifically wanted an example using an already filled dataset.
0
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
LVL 7

Expert Comment

by:culshaja
ID: 10666629
I use a simple routine that loops through the datatable and exports each row as a comma seperated row in a text file which I save as a .csv file (i.e. creating a CASV file). Works a treat.

James :-)
0
 

Author Comment

by:farawayman
ID: 10666674
James and Dabas,

Can you give an example?

Cheers
0
 
LVL 27

Expert Comment

by:Dabas
ID: 10666738
farawayman:
Assuming you have a DataSet named ds

        ds.WriteXml("MyXMLFile.xml")

You can now open MyXMLFile.xml in Excel

Dabas
0
 

Author Comment

by:farawayman
ID: 10666773
Okay cool - what about the prompting the user on where to save ...

...:-)
0
 

Author Comment

by:farawayman
ID: 10666791
Dabas,

Okay - I am now kinda liking xml .... cool - so easy .... but how do I handle those larger than life numbers that appear with Es in Excel - do you have any ideas.
0
 
LVL 7

Expert Comment

by:culshaja
ID: 10666796
I use the following code in the onclick event:

        Dim fs As New myFolderBrowser()
        fs.ShowDialog()

        If fs.DirectoryPath <> "" Then
            txtOutputFolder.Text = fs.DirectoryPath
        End If

And the following is the calss that creates the dialog box:


'************************************************************
'**
'** Code By Joe Griffith (jgriffit@pensoft.com)
'**
'** Posted in microsoft.public.dotnet.languages.vb
'**
'************************************************************

Imports System.Windows.Forms
Imports System.Windows.Forms.Design
Imports System.Windows.Forms.Design.FolderNameEditor
Imports System.IO

'+----------------------------------------------------+
'| F O L D E R B R O W S E R |
'+----------------------------------------------------+
'| This class displays the folder browser dialog |
'| which for some reason is not readily available in |
'| the .net framework. |
'| |
'| |
'| |
'+----------------------------------------------------+
Public Class myFolderBrowser
    Inherits FolderNameEditor
    Dim mo_FB As New FolderBrowser()

    Public Sub New()
        MyBase.new()
        mo_FB.Style = FolderNameEditor.FolderBrowserStyles.RestrictToFilesystem
        mo_FB.StartLocation = FolderBrowserFolder.Desktop ' Seems to be limited to this enumeration
    End Sub

    Public Sub ShowDialog()
        mo_FB.ShowDialog()
    End Sub

    Public ReadOnly Property DirectoryPath() As String
        Get
            Return mo_FB.DirectoryPath
        End Get
    End Property

    Public WriteOnly Property Description() As String
        Set(ByVal Value As String)
            mo_FB.Description = Value
        End Set
    End Property

End Class



James :-)
0
 
LVL 27

Expert Comment

by:Dabas
ID: 10666816
farawayman:

        Dim dlg As New OpenFileDialog
        dlg.Filter = "xml files (*.xml)|*.xml"
        dlg.ShowDialog()
        ds.WriteXml(dlg.FileName)

Dabas
0
 
LVL 27

Accepted Solution

by:
Dabas earned 2000 total points
ID: 10666828
farawayman:
> but how do I handle those larger than life numbers that appear with Es in Excel -

1) Highlight them
2) Right click
3) Format Cells...
4) Choose a format (for example Number with 2 decimal places)

Dabas
0
 
LVL 27

Expert Comment

by:Dabas
ID: 10666841
culshaja:
> '| which for some reason is not readily available in |
> '| the .net framework. |

Seems Mr Grifith did not know about the OpenFileDialog object!!!

Dabas
0
 

Author Comment

by:farawayman
ID: 10666863
Dabas,

I meant prior to opening in excel - but that's fine - you have helped loads.

James,

Dude thanks for the effort - I've gone for Dabas and am gonna give him 500 points.

But here's a question you can add a comment to and then I will give you 125 points for assistance.

http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/Q_20930142.html 

Thanks,

Steven
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

IP addresses can be stored in a database in any of several ways.  These ways may vary based on the volume of the data.  I was dealing with quite a large amount of data for user authentication purpose, and needed a way to minimize the storage.   …
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

610 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