Missing Method when importing

Imports ClosedXML.Excel 

Sub import()

    'Open the Excel file using ClosedXML.
    Using workBook As New XLWorkbook(file_pr)
        'Read the first Sheet from Excel file.
        Dim workSheet As IXLWorksheet = workBook.Worksheet(1)

        'Create a New DataTable.
        Dim dt As New DataTable()

        'Loop through the Worksheet rows.
        Dim firstRow As Boolean = True
        For Each row As IXLRow In workSheet.Rows()
            'Use the first row to add columns to DataTable.
            If firstRow Then
                For Each cell As IXLCell In row.Cells()
                firstRow = False
                'Add rows to DataTable.
                Dim i As Integer = 0
                For Each cell As IXLCell In row.Cells()
                    dt.Rows(dt.Rows.Count - 1)(i) = cell.Value
                    i += 1

            End If
    End Using
End Sub

When I'm importing excel using this query, appear error.

'Method not found:'DocumentFormat.OpenXml.OpenXmlElementList DocumentFormat.OpenXml.OpenXmlElement.get_ChildElements()'.'.

Please help me to solve it


  • I had the same problem. ClosedXML doesn't fully support the new DocumentFormat.OpenXML v3.0.0 release, which introduced some breaking changes.

    I fixed it by downgrading the version of the DocumentFormat.OpenXML package to 2.20.0.

    Related GitHub issue