Click here to Skip to main content
Rate this: bad
good
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
Comments
Jegan Thiyagesan at 25-Feb-13 8:35am
   
What have you tried?
   
Check this thread: http://www.codeproject.com/Questions/473945/xlsxplusfileplustoplus-xmlplusfileplusc-23
Guilherme Bovo Fernandez at 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
good
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
 
Cheers,
Edo
  Permalink  
Comments
Guilherme Bovo Fernandez at 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 at 26-Feb-13 0:20am
   
You can always manually build your xml.
Do you need sample code for that?
Sergey Alexandrovich Kryukov at 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)

  Print Answers RSS
0 George Jonsson 215
1 Kornfeld Eliyahu Peter 169
2 OriginalGriff 120
3 PIEBALDconsult 110
4 BillWoodruff 85
0 OriginalGriff 6,165
1 DamithSL 4,658
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,649
4 Sergey Alexandrovich Kryukov 3,294


Advertise | Privacy | Mobile
Web03 | 2.8.141220.1 | Last Updated 25 Feb 2013
Copyright © CodeProject, 1999-2014
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