Solved

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

Posted on 2004-03-24
13
1,256 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 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

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

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

Flash (http://en.wikipedia.org/wiki/Adobe_Flash) has evolved over the years to where it has become a masterful tool for displaying content screen.  It has excellent layout placement, UI precision as well as rendering capabilities. This, along with t…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…

828 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