Exemplo n.º 1
0
 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();
         }
     }
 }