Solved

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

Posted on 2004-03-24
13
1,257 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
Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

 
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

Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

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…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
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…

756 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