Saturday, June 20, 2009

Converting Excel file into Xml

You can Easily convert Excel Sheet into Xml File by One Click
I am Writing That code Here.

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

Dim Str As String = Nothing
Dim src, src2 As String
src = txtExcel.Text// name of .xls File
src2 = txtTablename.Text//name Excel Sheet it take multiple sheet name with seprated by comma




Str = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & src & ";Extended Properties=Excel 8.0;"//connecting to Excel
Dim stringItems() As String = src2.Split(",")

Dim count As Integer
For count = 0 To stringItems.Length - 1

Dim dx As New DataSet()

Dim DA As New OleDb.OleDbDataAdapter()
Dim DS As New DataSet()

Dim str2 As String
str2 = "$"
Dim objConn As New OleDb.OleDbConnection(Str)
Dim scomman As String = "select * from [" + stringItems(count) + "$]"
Dim ada As New OleDbDataAdapter(scomman, objConn)

ada.Fill(dx, "transport")

Dim doc As New XmlDataDocument(dx)
doc.Save("C:\" + stringItems(count) + ".xml")

Next

MsgBox("Xml Files Created", MsgBoxStyle.Information, "Xml Converter")


End Sub

0 comments:

Post a Comment

plzz give the comment