Skip to content

Read XML Data and Pass to excel

chen boly

Asked May 1, 2012, 7:46 PM EDT2 answers
Share
LinkedInX
Dear All,

I am a very new in C#, I use to try only in VBA in excel.

how to write code using visual C# use Windows Application Form to read XML data in XML file and pass to Excel worksheet?

Thanks and Best Regards;
BL

2 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    XNamespace ss = "urn:schemas-microsoft-com:office:spreadsheet"; XDocument sheet = XDocument.Load(@"YourXMLFile.xml"); foreach (XElement worksheet in sheet.Root.Elements(ss + "Worksheet")) { Console.WriteLine("Worksheet: {0}", worksheet.Attribute(ss + "Name").Value); foreach (XElement row in worksheet.Element(ss + "Table").Elements(ss + "Row")) { foreach (XElement cell in row.Elements(ss + "Cell")) { Console.Write("{0}\t", cell.Value); } Console.WriteLine(); } Console.WriteLine(); }
    0
  • 0
    Dear vijay bhardwaj,

    Thank you for your response. However, like I mention in my first post, I am very new in C#, I really not understand about your code.

    If you don't mind, could you please provide me the example to read the XML file as in attached.

    I just want to read all the value in "=Value" attribute in XML and pass the data into worksheet (excel) respectively by the StationName.

    Example: Worksheet Name CSA must be store value from CSA in XML file.

    Hope you can help.

    Best Regards;
    BL
    0