private void BtnGetSheets_Click(object sender, EventArgs e) { if (ValidationLogic.InvalidFile(TbxFilePath)) { ErrorActions.InvalidFile(); } else { try { /* using form inputs open the file and loop through all sheets within * the workbook, adding the name of each sheet encountered into a list * box that the user can select from. */ string file = TbxFilePath.Text.ToString(); ExcelThread.OpenWorkbook(file); ExcelThread.GetSheets(); LbxSheetNames.Items.Clear(); for (int i = 1; i <= ExcelThread.Worksheets.Count; i++) { Microsoft.Office.Interop.Excel.Worksheet sheet = ExcelThread.Worksheets[i]; LbxSheetNames.Items.Add(sheet.Name.ToString()); } // make the next stage of the process/application visible. GrpSheetAndHeader.Visible = true; } catch { ErrorActions.FailOpenFile(); } } }
/* this method is designed to allow the user to perform a soft reset and reset * the application to the state direcly after pressin the 'get headers or * columns' button. The intent is to allow mutiple agings of the same data * making use of different headers on subsquent agings. */ private void ReAgeCurrentFileToolStripMenuItem_Click(object sender, EventArgs e) { // subset of get sheets button event. ExcelThread.Reset(); string file = TbxFilePath.Text.ToString(); ExcelThread.OpenWorkbook(file); ExcelThread.GetSheets(); // subset of the get headers button event. if (ValidationLogic.NoItemSelected(LbxSheetNames)) { ErrorActions.NoSheetSelected(); } else { string sheetWithData = LbxSheetNames.SelectedItem.ToString(); ExcelThread.Worksheet = ExcelThread.Worksheets[sheetWithData]; if (ValidationLogic.NoColumnsFound(ExcelThread.Worksheet)) { ErrorActions.NoColumnsFound(); } else { BuildHeaders(); PrepForAging(); } } }