C# to convert xml to excel?

Asked By 80 points N/A Posted on -
qa-featured

Hello,

I have some data in xml and I need to convert it to excel format. I also need to carry out sorting and filtering on my excel spreadsheet.

How can do it? Please provide me the C# codes to convert xml to Excel.

Thanks.

SHARE
Best Answer by Phillip Taylor
Answered By 0 points N/A #146450

C# to convert xml to excel?

qa-featured

Hi Glenda

You can use the piece of code below for converting your xml file into excel format.

private static void Convertxmlintoxls()

{

    // Read xml file. Convert to excel and save

    XLSDocument docname = new XLSDocument();

    SimpleXMLConverter converter = new SimpleXMLConverter(docname);

    converter.LoadXML("YOUR XML FILE PATH");

    //Check if xls file already exist.Delete it

    File.Delete("YOUR XLS FILE PATH");

    docname.SaveAs("YOUR XLS FILE PATH");

    docname.Close();

}

Best Answer
Best Answer
Answered By 0 points N/A #146451

C# to convert xml to excel?

qa-featured

 

Hi Glenda W Larson

Here is a easy converter class (C#, full source code) to assist you alter XML data into XLS and XLS into XML

Download full source code of this example (alongside with SimpleXMLConverter class source code) here: 
http://bytescout.com/files/examples/bytescoutxls_convert_xml_to_xls.zip (9 KB)

#1 example (converting XML into XLS):
——————–
private static void SampleXMLtoXLSConversion()
{
// read XML and convert into XLS (Excel) and save

XLSDocument document = new XLSDocument();

SimpleXMLConverter tools = new SimpleXMLConverter(document);

tools.LoadXML("AdvancedReport.xml");

File.Delete("AdvancedReportFromXML.xls");
document.SaveAs("AdvancedReportFromXML.xls");

document.Close();
}

Thanks

Login/Register to Answer

Related Questions