如何使用Open XML获取特定行上的列的单元格引用?
我有一个Excel,
ABCD -- --- --- --- 3 4 7 8 9 10
在Interop.Excel中使用。
xlSheet.Cells(1, 3).Formula.ToString
获得结果为3 OR的第1行第3列的值
xlSheet.Cells(1, 2).Formula.ToString
获得第1行第2列的值,结果将是空string
我如何使用Open XML去解决这个问题?
用openxml你有.RowId和.ColumnIdselect一个特定的单元格,使用LINQ应该允许你操纵你的数据。 有关详细示例,请参阅http://openxmldeveloper.org/blog/b/openxmldeveloper/archive/2011/07/18/query-open-xml-spreadsheets-in-vb-net-using-linq.aspx
再次查看后,此解决scheme应该工作
Using doc As SpreadsheetDocument = SpreadsheetDocument.Open("Data.xlsx", False) Dim worksheet As WorksheetPart = doc.WorkbookPart.GetPartById(0) Dim cell as Cell = worksheet.rows(yourRow).collumns(yourCollumn) return cell.value End using
如果没有,也许你将不得不做一个foreach循环,但如果你有大量的数据,这不会是明智的