private void ReadSheetNames() { SheetNames.Clear(); SelectedSheetName = string.Empty; try { ExcelReader.ReadSheetNames(selectedFile).ForEach(SheetNames.Add); if (SheetNames.Count > 0) { if (SheetNames.Contains("Лист1")) { SelectedSheetName = "Лист1"; } else if (SheetNames.Contains("Данные")) { SelectedSheetName = "Данные"; } else { SelectedSheetName = SheetNames[0]; } } } catch (Exception exc) { MessageBox.Show( this, exc.Message + Environment.NewLine + exc.StackTrace, "Ошибка считывания Excel файла", MessageBoxButton.OK, MessageBoxImage.Error); } }
public void SelectWorkbookFile() { SheetNames.Clear(); SheetNamesComboboxEnabled = false; SelectedSheetName = string.Empty; OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Filter = "Книга Excel (*.xls*)|*.xls*"; openFileDialog.CheckFileExists = true; openFileDialog.CheckPathExists = true; openFileDialog.Multiselect = false; openFileDialog.RestoreDirectory = true; if (openFileDialog.ShowDialog() == true) { TextWorkbookPath = openFileDialog.FileName; ExcelGeneral.ReadSheetNames(TextWorkbookPath).ForEach(SheetNames.Add); SheetNamesComboboxEnabled = true; if (SheetNames.Count > 0) { SelectedSheetName = SheetNames[0]; } } }
private void ButtonSelectFile_Click(object sender, RoutedEventArgs e) { SheetNames.Clear(); SelectedFile = string.Empty; OpenFileDialog openFileDialog = new OpenFileDialog { Filter = "Книга Excel (*.xls*)|*.xls*", CheckFileExists = true, CheckPathExists = true, Multiselect = false, RestoreDirectory = true }; if (openFileDialog.ShowDialog() == true) { SelectedFile = openFileDialog.FileName; ReadSheetNames(); } }
private void UpdateSheetNames() { SheetNames.Clear(); if (_workbook == null) { SelectedSheetIndex = -1; IsFileLoaded = false; return; } foreach (var sheet in _workbook.Worksheets) { SheetNames.Add(sheet.Name); } IsFileLoaded = true; SelectedSheetIndex = 0; }