0

我遇到了与名为“Libro1.xlsx”的 excel 2007 文件相关的以下问题。在这个文件中,我已经将第一张表中的单元格 A1 设置为“hello world”,id 为“rId1”,单元格 A2 设置为“500”。

在下面的代码中,您将看到我正在访问此工作表的每一行和单元格。我得到单元格 A2 = 500 的内容作为输出,但不是 A1 单元格的内容(我得到“0”作为值)。

这是我使用的代码:

' 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

您是否知道为什么我没有在 A1 单元格上设置文本?

4

1 回答 1

2

Excel 使用SharedStringTable来存储非数值。检查示例方法

字符串 XLGetCellValue(Excel.Cell c,WorkbookPart wbPart)

在这里使用 ShareStringTable

于 2012-06-08T13:54:40.627 回答