Basit Khan

Basit Khan

  • 1.3k
  • 336
  • 115.6k

Data export from Excel to XML

Jan 30 2018 2:24 AM
Hi,
 
I wrote the below code to export data from excel to xml, but in excel file if column cell is empty then in xml that column/element is not showing.
 
i want whereever empty cell in xml should show as 0 
  1. Private Function exportExceltoXML(ByVal excelPath As StringAs String  
  2. Dim cnExcel As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + excelPath + ";Extended Properties=Excel 12.0;")  
  3. cnExcel.Open()  
  4. Dim ds As New DataSet  
  5. Dim da As New OleDbDataAdapter("SELECT * FROM [Sheet1$]", cnExcel)  
  6. da.Fill(ds)  
  7. cnExcel.Close()  
  8. Dim sXML As String  
  9. sXML = ds.GetXml()  
  10. ds.WriteXml(TextBox1.Text & "\Trn_Daily3.xml")  
  11. ds.Dispose()  
  12. da.Dispose()  
  13. MsgBox("Exported successfully")  
  14. Return sXML  
  15. End Function  
Thanks
Basit. 

Answers (4)