private void ReadCompareExcelToDictionary()
{
if (File.Exists(oldFileTxt.Text))
{
sourceSheetDicionary = new Dictionary<object, Dictionary<object, object[]>>();
// Opening the excel file. in excel version 5.0.0 it takes 15 arguments some of which like filepath, format, origin etc are mandatory, other you can put null or 0.
Excel.Workbook theWorkBook = _exlObj.Workbooks.Open(oldFileTxt.Text, 0, true, 5, "", "", true,
Excel.XlPlatform.xlWindows, "/t", false, false, 0,
true, null, null);
// Extracting the worksheet collection out of workbook, there can be any number of worksheet in a workbook
Excel.Sheets sheets = theWorkBook.Worksheets;
progressBar1.Maximum = sheets.Count;
// Iterating for each worksheet
for (int index = 1; index <= sheets.Count; index++)
{
Excel.Worksheet workSheet = (Excel.Worksheet) sheets.get_Item(index);
Messagelbl.Text = "Reading worksheet:" + workSheet.Name;
progressBar1.Value = index;
Refresh();
Dictionary<object, object[]> sheetDictionary = ReadWorkSheetToDictionary(workSheet);
sourceSheetDicionary.Add(workSheet.Name, sheetDictionary);
}
_exlObj.Workbooks.Close();
}
}