How to deserialize Excel file to 2-dimensional array?
I have an Excel wor开发者_Python百科ksheet where all the fields are strings. I would like to de-serialize all the data from the excel file to a 2D array (matrix).
Any ideas how I can get started?
If your Excel file is built like a table, you can use ADO.NET to access your Excel file like a database and pull your data via SQL.
Excel 97-2003: http://connectionstrings.com/excel#p21
Excel 2007+: http://connectionstrings.com/excel-2007#p20
If you're trying to open a .xlsx file, you should use the Open Xml SDK.
If you're trying to open a .xls file, I recommend saving yourself some headaches and checking out filehelpers.sourceforge.net.
You can do
Sub ReadArray()
Dim MyArray As Variant
MyArray = Sheets(1).Range("A1").CurrentRegion
End Sub
[]'s
精彩评论