Retrieve cell value issue with open xml sdk

故事扮演 提交于 2020-06-18 16:56:40

问题


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?


回答1:


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

string XLGetCellValue(Excel.Cell c, WorkbookPart wbPart)

to use ShareStringTable here



来源:https://stackoverflow.com/questions/10948129/retrieve-cell-value-issue-with-open-xml-sdk

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!