Solved

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

Posted on 2004-03-24
13
1,245 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
Comment Utility
0
 
LVL 27

Expert Comment

by:Dabas
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
James and Dabas,

Can you give an example?

Cheers
0
 
LVL 27

Expert Comment

by:Dabas
Comment Utility
farawayman:
Assuming you have a DataSet named ds

        ds.WriteXml("MyXMLFile.xml")

You can now open MyXMLFile.xml in Excel

Dabas
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

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

...:-)
0
 

Author Comment

by:farawayman
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Summary Displaying images in RichTextBox is a common requirement with limited solutions available. Pasting through clipboard or embedding into RTF content only support static images.  This article describes how to insert Windows control objects int…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
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.

763 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

13 Experts available now in Live!

Get 1:1 Help Now