如何在可视化和C#中将XLSX转换为XML [英] How to Convert XLSX to XML in visual studion and C#
本文介绍了如何在可视化和C#中将XLSX转换为XML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要使用C#和Visual Studio 2010将一些表(XLSX)转换为XML。
我还需要检查列名是否正确,但我的主要问题是转换,我找到了一些解决方案,但没有找到解决方案。
I need to convert some tables (XLSX) to XML using C# and Visual Studio 2010.
And also I need to check if the column name are right, but my main problem is the conversion, I''ve found some solutions, but none worked.
推荐答案
Hello Guilherme,
没有开箱即用的解决方案,因为不清楚你需要什么样的xml架构。
但是,这很简单,因为你可以轻松实现:
1.用C#读取excel
2.用C#创建你的xml文件
她是一个例子阅读excel:
Hello Guilherme,
There is no out of the box solution, as it is not clear what xml schema you need.
However, that is fairly simple, since you can easily implement:
1. reading the excel with C#
2. create your xml file with C#
Hers''s an example for reading an excel:
var fileName = string.Format("{0}\\fileNameHere", Directory.GetCurrentDirectory());
var connectionString = string.Format("Provider=Microsoft.Jet.OLEDB.4.0; data source={0}; Extended Properties=Excel 8.0;", fileName);
var adapter = new OleDbDataAdapter("SELECT * FROM [workSheetNameHere
,connectionString);
var ds = new DataSet();
adapter.Fill(ds, anyNameHere);
DataTable data = ds.Tables [ anyNameHere];
", connectionString); var ds = new DataSet(); adapter.Fill(ds, "anyNameHere"); DataTable data = ds.Tables["anyNameHere"];
如果您希望可以实现自己的xml架构或使用 Datatable.WriteXml
方法
干杯,
Edo
If you wish you can either implement your own xml schema or use Datatable.WriteXml
method
Cheers,
Edo
这篇关于如何在可视化和C#中将XLSX转换为XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文