Click here to Skip to main content
15,881,600 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My xml document contain this kind of scenario:
XML
<Employee>
 <Name>
  <FirstName>George</FirstName>
  <LastName> Desh </LastName>
 </Name>
 <Address>
   <State>
     <city>Pune</city>
     <Dist>Pune</Dist>
   </State>
 </Address>
</Employee>


So how my excel will look for this nested xml elements. And how we can convert this xml into excel using C#?
Posted
Comments
Patrice T 31-Aug-15 13:59pm    
Why not somply open the xml file directly in Excel ?

1 solution

Please use the following code generating excel file based on the xml.


public void XMLToExcel(string strXMLPath, string outputFileName, string sheetName)
{
string strPath = Path.GetDirectoryName(strXMLPath);
DataSet dsXML = new DataSet();
dsXML.ReadXml(strXMLPath);
strPath = strPath + "\\" + outputFileName + ".xlsx";
DataTable tblXML = dsXML.Tables[0];
tblXML.TableName = sheetName;
DataTableToFilePath(tblXML, strPath);
}
 
Share this answer
 

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