I want to put some numbers from Excel to array.
Let’s say I have an Excel file with some numbers like this:
23
34
1
3
100
56
45
43
56
4
87
6
89
9
this is just one column in excel (or any file)
And i want to put those numers in arraylist as integer numbers, i dont need the result as one number but all those numbers to be in int value.
Any help please ?
Assuming that the above is a string (and the source does not matter), you can do the following:
I suggest using
List<int>instead ofArrayListfor type safety.The following code reads all values from an Excel sheet into a data set using a DB connection. You can then pick the value needed.:
EDIT
You did not specify the exact source for the string, so if this question is about how to read a file or how to import data from an Excel spreadsheet, you should probably rephrase your question a little.
EDIT 2
Replaced
List<int>byArrayListon OP’s wish (against better design).EDIT 3
Added a new line to show the OP how to use the
ArrayListas a data source for aListBox…EDIT 4
Added code to read Excel sheet using OleDB.