0
我一直在尋找一種能夠有效讀取Excel文件並找到了解析下面的代碼,閱讀了大量的電子表格:VB.NET的OpenXML讀取Excel文件
公用Sub ExcelProcessing()
Dim strDoc As String = "C:\Documents and Settings\Practice.xlsx"
Dim txt As String
Dim spreadsheetDocument As SpreadsheetDocument = spreadsheetDocument.Open(strDoc, False)
Dim workbookPart As WorkbookPart = spreadsheetDocument.WorkbookPart
Dim worksheetPart As WorksheetPart = workbookPart.WorksheetParts.First()
Dim reader As OpenXmlReader = OpenXmlReader.Create(worksheetPart)
Dim text As String
While reader.Read()
If reader.ElementType = GetType(CellValue) Then
text = reader.GetText()
MessageBox.Show(text)
End If
End While
的問題是,我分配reader.GetText()來我的字符串。傳遞的值是一個小整數,而實際的單元格值是一個字符串。消息框會爲每個填充的單元格觸發一次,所以這告訴我代碼正在找到包含值的單元格;但是,我無法提取單元格的實際「內部文本」。
想法?建議?
看起來這篇文章。 ([鏈接] http://www.codeproject.com/Articles/15593/Read-and-write-Open-XML-files-MS-Office-2007)回答我的問題,雖然我仍然需要看看我是什麼我正在嘗試可以用OpenXmlReader完成。任何指導將不勝感激! – 2013-03-21 21:48:57