How to create an XML file from Excel

XML is a general purpose tag based language and very easy to transfer and store data across applications. The .Net Framework provides the Classes for read, write, and other operations in XML formatted files .

The following program shows how to create an XML file from an Excel file content . Here we are using an OleDbConnection to read the excel file and store the content to a Dataset . Call the method WriteXml of Datset to write to the XML file.

Imports System.Data
Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim MyConnection As System.Data.OleDb.OleDbConnection
            Dim ds As System.Data.DataSet
            Dim MyCommand As System.Data.OleDb.OleDbDataAdapter
            MyConnection = New System.Data.OleDb.OleDbConnection _
            ("provider=Microsoft.Jet.OLEDB.4.0;Data Source='xl2xml.xls';Extended Properties=Excel 8.0;")
            MyCommand = New System.Data.OleDb.OleDbDataAdapter _
                ("select * from [Sheet1$]", MyConnection)
            MyCommand.TableMappings.Add("Table", "Product")
            ds = New System.Data.DataSet
        Catch ex As Exception
        End Try
    End Sub
End Class

Click here to download the input excel file xl2xml.xls (C) 2021    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.
SiteMap  | Terms  | About