Click here to Skip to main content
15,883,883 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
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.
Posted
Comments
Jegan Thiyagesan 25-Feb-13 8:35am    
What have you tried?
José Amílcar Casimiro 25-Feb-13 8:45am    
Check this thread: http://www.codeproject.com/Questions/473945/xlsxplusfileplustoplus-xmlplusfileplusc-23
Guilherme Bovo Fernandez 25-Feb-13 15:00pm    
I've tried the 1st Solution since 3rd does not apply for my need and didn't understand the 2sc one.

1 solution

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:
C#
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"];


If you wish you can either implement your own xml schema or use Datatable.WriteXml method

Cheers,
Edo
 
Share this answer
 
Comments
Guilherme Bovo Fernandez 25-Feb-13 14:50pm    
I'm reading excel using OLEDB by now. But, I don't know how to create the XML file, I've tried OLEDB but it did not work to create XML.

I need to do the following :

EstimatedBeginTime | EstimatedEndTime | VehiclePlate | ....
21/07/2011 10:30:00 | 21/07/2011 16:00:00 | BMW-0001 | ....

and returns XML like this :

<Trip EstimatedBeginTime="21/07/2011 10:30:00"
EstimatedEndTime="21/07/2011 16:00:00" VehiclePlate="BMW-0001">
Joezer BH 26-Feb-13 0:20am    
You can always manually build your xml.
Do you need sample code for that?
Sergey Alexandrovich Kryukov 26-Feb-13 2:00am    
5ed.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900