i am retrieving information from an excel sheet,
i want to take the information from the excel sheet and insert it in a 2 dementional array so i can use it later.
it always start filling from the row [1,1] and ignore the rest. any idea how i can make it start from [0,0]. this is the code i am using.
if ((myStream = openFileDialog1.OpenFile()) != null)
{
using (myStream)
{
var strs = openFileDialog1.InitialDirectory;
var name = openFileDialog1.FileName;
var path = strs + name;
Excel.Application xlApp;
Excel.Workbook xlWorkBook;
Excel.Worksheet xlWorkSheet;
Excel.Range range;
string str = "";
int rCnt = 0;
int cCnt = 0;
xlApp = new Excel.Application();
xlWorkBook = xlApp.Workbooks.Open(path, 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);
xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
range = xlWorkSheet.UsedRange;
Hashtable myHT = new Hashtable();
int countRow = 0;
string[,] myArray;
myArray = new string[range.Rows.Count, range.Columns.Count];
for (rCnt = 1; rCnt <= range.Rows.Count; rCnt++)
{
for (cCnt = 1; cCnt <= range.Columns.Count; cCnt++)
{
//str = (string)(range.Cells[rCnt, cCnt] as Excel.Range).Value2;
myArray[cCnt, rCnt] = (string)(range.Cells[rCnt, cCnt] as Excel.Range).Value2;
//MessageBox.Show(str);
}
countRow++;
}
label1.Text = Convert.ToString(countRow);
xlWorkBook.Close(true, null, null);
xlApp.Quit();
Simply change the line:
to: