Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm learning how to convert an ODS file into a DataGridView. I've already learned how to open the ods file and extract the XML file. I can't figure out how to take any data with texts and turn it into rows and columns on a DataGridView. I just need the data, not the formatting or anything. Can you help me?

This is a part of content.xml file:

XML
<office:body>
<office:spreadsheet>

<table:calculation-settings table:use-wildcards="true" 
table:use-regular-expressions="false" table:automatic-find-labels="false"/>

<table:table table:name="Foglio1" table:style-name="ta1">

<table:table-column table:style-name="co1" 
table:default-cell-style-name="Default" 
table:number-columns-repeated="8"/>

<table:table-row table:style-name="ro1">

<table:table-cell calcext:value-type="string" 
office:value-type="string">

<text:p>Carota</text:p>

</table:table-cell>

<table:table-cell calcext:value-type="string" office:value-type="string">

<text:p>Sedano</text:p>

</table:table-cell>

<table:table-cell calcext:value-type="string" office:value-type="string">

<text:p>Cipolla</text:p>

</table:table-cell>

<table:table-cell table:number-columns-repeated="4"/>

<table:table-cell calcext:value-type="string" office:value-type="string">

<text:p>Aglio</text:p>

</table:table-cell>

</table:table-row>

</table:table>

<table:named-expressions/>

</office:spreadsheet>

</office:body>


What I have tried:

VB
Dim luogo As String = My.Application.Info.DirectoryPath & "\Estratti\content.xml"
Dim x = XDocument.Load(luogo)

For Each element In x.<office:document-content>.<office:body>.<office:spreadsheet>.
  <table:table>.<table:table-row>.<table:table-cell>

    For Each attr As XAttribute In element.Attributes
        If attr.Name.LocalName = "number-columns-repeated" Then
            Console.WriteLine(vbTab & attr.Name.LocalName & " : " & attr.Value)
            Dim aggiunto As Integer = attr.Value

        End If

    Next

    Console.WriteLine(element.Value)
Next
Posted
Updated 2-Oct-23 5:24am
v3

1 solution

You just need to build the DataGridView Control - Windows Forms .NET Framework | Microsoft Learn[^] columns and rows, and add the data that you want to display.
 
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