Click here to Skip to main content
11,933,854 members (56,594 online)
Rate this:
Please Sign up or sign in to vote.
See more: C# XML convert conversion
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 25-Feb-13 3:30am
Jegan Thiyagesan 25-Feb-13 8:35am
What have you tried?
Check this thread:
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

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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"];

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

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">
Edo Tzumer 26-Feb-13 0:20am
You can always manually build your xml.
Do you need sample code for that?

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web03 | 2.8.151126.1 | Last Updated 25 Feb 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100