Jose3d
Jose3d

Reputation: 9277

Retrieve cell value issue with open xml sdk

Im having the following issue related with an excel 2007 file called "Libro1.xlsx". On this file i already set to "hello world" the cell A1 in the first sheet with id "rId1" and cell A2 to "500".

In the following code you'll see that im accesing every row and cell of this sheet. Im getting as output the content of the cell A2 = 500 but not the content of the A1 cell (im getting "0" as value).

Here the code that im using:

' Open the document for editing.
        Dim ficheroexcel As SpreadsheetDocument = SpreadsheetDocument.Open(Server.MapPath("Libro1.xlsx"), True)
        Try
            Dim libroconhojas As WorkbookPart = ficheroexcel.GetPartsOfType(Of WorkbookPart).First()
            Dim hoja1 As WorksheetPart = libroconhojas.GetPartById("rId1")
            Dim hoja2 As WorksheetPart = libroconhojas.GetPartById("rId2")
            Dim hoja3 As WorksheetPart = libroconhojas.GetPartById("rId3")
            'hoja.SingleCellTablePart
            Dim hojadatos1 As SheetData = hoja1.Worksheet.GetFirstChild(Of SheetData)()
            Dim hojadatos2 As SheetData = hoja2.Worksheet.GetFirstChild(Of SheetData)()
            Dim hojadatos3 As SheetData = hoja3.Worksheet.GetFirstChild(Of SheetData)()

            Dim fila As Row
            Dim celda As Cell
            For Each fila In hojadatos1.Elements(Of Row)()
                For Each celda In fila.Elements(Of Cell)()
                    Response.Write("texto:" + celda.InnerText + "</br>")
                Next
            Next
            Dim algo = ""
        Catch ex As Exception

        Finally
            ficheroexcel.Close()
        End Try

Do you have any clue about why im not getting the text set on the A1 cell?

Upvotes: 0

Views: 592

Answers (1)

Kiru
Kiru

Reputation: 3565

Excel uses SharedStringTable to store non numeric values. Check the example method

string XLGetCellValue(Excel.Cell c, WorkbookPart wbPart)

to use ShareStringTable here

Upvotes: 2

Related Questions