/// <summary> /// Uses OpenXml to read sheet names, extremely fast, /// the vb.net xml example is just as fast. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void cmdGetSheetNamesXml_Click(object sender, EventArgs e) { var helper = new OpenXmlExamples(); var fileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Customers.xlsx"); var sheetNames = helper.SheetNames(fileName); if (helper.IsSuccessFul) { sheetNames.Insert(0, "Select sheet"); cboGetSheetNamesXml.DataSource = sheetNames; } else { Dialogs.ExceptionDialog(helper.LastException); } }
/// <summary> /// Setup /// * Get fresh copies of Excel files. /// * Get sheet names from Customers.xlsx via OpenXml /// * Setup a timer to watch for Excel processes open. /// This assumes you don't have Excel open outside this app. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Form1_Shown(object sender, EventArgs e) { timerForExcel.Enabled = true; /* * Start with a clean slate in regards to base Excel files */ _fileOperations.RemoveExcelFiles(); /* * These files were not copied over */ _fileOperations.RemoveOtherExcelFiles(new[] { "Cust.xlsx", "PeopleDemo.xlsx", "BadPeopleDemo.xlsx", "Customers.xml" }); /* * Copy files from base file folder */ _fileOperations.CopyExcelFiles(); if (_fileOperations.HasException) { MessageBox.Show($"Issues with file delete/copy{Environment.NewLine}{_fileOperations.LastExceptionMessage}"); } var fileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Customers.xlsx"); /* * There is also an automated method that does the * same as this in ExcelBase class. This method was * used as it's faster than using automation. */ var helper = new OpenXmlExamples(); var sheetNames = helper.SheetNames(fileName); sheetNames.Insert(0, "Select sheet"); cboCustomerSheetNames.DataSource = sheetNames; }