locked
office excel xml table RRS feed

  • Question

  •  

    how can I get an element from a  excel xml table?how to use  xml namespaces??can anyone help me??
    Friday, August 15, 2008 5:01 PM

Answers

  • Here is a simple VB.NET LINQ to XML program that prints out the data from table cells in an Excel spreadsheet in Excel 2003 XML format:

    Code Snippet

    Imports System
    Imports System.Xml.Linq
    Imports <xmlns="urn:schemas-microsoft-com:office:spreadsheet">

    Module Module1

        Sub Main()
            Dim workbook As XElement = XElement.Load("..\..\XMLFile1.xml")
            For Each table As XElement In workbook.<Worksheet>.<Table>
                For Each row As XElement In table.<Row>
                    For Each cell In row.<Cell>
                        Console.Write("{0}" & vbTab, cell.<Data>(0).Value)
                    Next
                    Console.WriteLine()
                Next
            Next

        End Sub

    End Module

     

     

    Friday, August 15, 2008 5:32 PM

All replies

  • Which version of the .NET framework do you want to use (e.g. 3.5 or 2.0)? For instance with 3.5 you can use LINQ to XML to query XML.

    And which programming language do you want to use, C# or VB.NET?

    And which Excel version is that, Excel 2003 or 2007?

    Friday, August 15, 2008 5:08 PM
  • Here is a simple VB.NET LINQ to XML program that prints out the data from table cells in an Excel spreadsheet in Excel 2003 XML format:

    Code Snippet

    Imports System
    Imports System.Xml.Linq
    Imports <xmlns="urn:schemas-microsoft-com:office:spreadsheet">

    Module Module1

        Sub Main()
            Dim workbook As XElement = XElement.Load("..\..\XMLFile1.xml")
            For Each table As XElement In workbook.<Worksheet>.<Table>
                For Each row As XElement In table.<Row>
                    For Each cell In row.<Cell>
                        Console.Write("{0}" & vbTab, cell.<Data>(0).Value)
                    Next
                    Console.WriteLine()
                Next
            Next

        End Sub

    End Module

     

     

    Friday, August 15, 2008 5:32 PM