当前位置: 移动技术网 > IT编程>开发语言>c# > C#读取Excel并转化成XML的方法

C#读取Excel并转化成XML的方法

2019年07月18日  | 移动技术网IT编程  | 我要评论

本文实例讲述了c#读取excel并转化成xml的方法。分享给大家供大家参考。具体实现方法如下:

复制代码 代码如下:
xmldocument exceldata = new xmldocument();
dataset exceltabledataset = new dataset();
streamreader excelcontent = new streamreader(excelfilepath, system.text.encoding.default);
string stringconnecttoexcelfile = string.format("provider=microsoft.ace.oledb.12.0;data source=" + excelfilepath + ";extended properties="excel 12.0;"");
system.data.oledb.oledbconnection oleconnectiontoexcelfile = new system.data.oledb.oledbconnection(stringconnecttoexcelfile);
system.data.oledb.oledbdataadapter oledataadapterforgetexceltable = new system.data.oledb.oledbdataadapter(string.format("select * from [sheet 1$]"), oleconnectiontoexcelfile);
try
{
    oledataadapterforgetexceltable.fill(exceltabledataset);
}
catch
{
    return null;
}
string exceloutputxml = path.gettempfilename();
exceltabledataset.writexml(exceloutputxml);
exceldata.load(exceloutputxml);
file.delete(exceloutputxml);
return exceldata;

希望本文所述对大家的c#程序设计有所帮助。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网