数据从excel导出到XML [英] Data export from excel to XML
本文介绍了数据从excel导出到XML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我编写了以下代码将数据从excel导出到xml,但是在excel文件中,如果列单元格为空,那么在xml中该列/元素没有显示。
i想要excel中的空单元格在xml中显示0。
谢谢
Basit。
我尝试过:
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 excel should show 0 in xml.
Thanks
Basit.
What I have tried:
Private Function exportExceltoXML(ByVal excelPath As String) As String
Dim cnExcel As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + excelPath + ";Extended Properties=Excel 12.0;")
cnExcel.Open()
Dim ds As New DataSet
Dim da As New OleDbDataAdapter("SELECT * FROM [Sheet1$]", cnExcel)
da.Fill(ds)
cnExcel.Close()
Dim sXML As String
sXML = ds.GetXml()
ds.WriteXml(TextBox1.Text & "\Trn_Daily3.xml")
ds.Dispose()
da.Dispose()
MsgBox("Exported successfully")
Return sXML
End Function
推荐答案
,cnExcel)
da.Fill(ds)
cnExcel.Close()
Dim sXML As String
sXML = ds.GetXml()
ds.WriteXml(TextBox1.Text& \Trn_Daily3.xml)
ds.Dispose()
da.Dispose()
MsgBox(导出成功)
返回sXML
结束函数
", cnExcel) da.Fill(ds) cnExcel.Close() Dim sXML As String sXML = ds.GetXml() ds.WriteXml(TextBox1.Text & "\Trn_Daily3.xml") ds.Dispose() da.Dispose() MsgBox("Exported successfully") Return sXML End Function
嗯...... Excel 2007(及更高版本)使用OpenXml格式,这意味着Excel文件实际上是 - 一个xml文件。
请参阅:办公室介绍(2007)Open XML File Formats [ ^ ]
我强烈建议您阅读:如何将Excel中的excel文件转换为xml格式,Visual Studio 2012的VB.NET [ ^ ]
Well... Excel 2007 (and higher) uses OpenXml format, which means that Excel file is - in a fact - an xml file.
See: Introducing the Office (2007) Open XML File Formats[^]
I'd strongly recommend to read this: How to convert excel file to xml format in C#, VB.NET for Visual Studio 2012[^]
这篇关于数据从excel导出到XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文