2

I have an Excel worksheet 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?

Rob
  • 5,223
  • 5
  • 41
  • 62
MoShe
  • 6,197
  • 17
  • 51
  • 77

3 Answers3

2

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.

Kyle Trauberman
  • 25,414
  • 13
  • 85
  • 121
2

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

Idan Arye
  • 12,402
  • 5
  • 49
  • 68
-3

You can do

Sub ReadArray()

Dim MyArray As Variant

MyArray = Sheets(1).Range("A1").CurrentRegion

End Sub

[]'s

Bruno Leite
  • 1,403
  • 13
  • 17
  • 2
    -1. The question asks for C#, this code *seems* incomplete, and the question gives no context (eg. API used?) – Rob Oct 11 '11 at 23:04