Solved

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

Posted on 2004-03-24
13
1,252 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
  • 5
  • 5
  • 2
  • +1
13 Comments
 
LVL 69

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
 
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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

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 500 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

910 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

18 Experts available now in Live!

Get 1:1 Help Now