Пример #1
0
        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];
                }
            }
        }
Пример #2
0
        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);
            }
        }
Пример #3
0
 private void loadInit()
 {
     getWorkbookInstance();
     if (workbook != null)
     {
         int num = workbook.NumberOfSheets;
         for (int k = 0; k < num; k++)
         {
             SheetNames.Add(workbook.GetSheetName(k));
         }
     }
 }
 private void OnSelectedSheetChanged()
 {
     if (string.IsNullOrEmpty(SelectedSheet))
     {
         IsValid = false;
     }
     if (!SheetNames.Contains(SelectedSheet))
     {
         IsValid = false;
     }
     IsValid = true;
 }
Пример #5
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;
        }
Пример #7
0
        protected override IAsyncResult BeginExecute(AsyncCodeActivityContext context, AsyncCallback callback, object state)
        {
            PropertyDescriptor property = context.DataContext.GetProperties()[ExcelCreate.GetExcelAppTag];
            Excel::Application excelApp = property.GetValue(context.DataContext) as Excel::Application;

            try
            {
                List <string> list = new List <string>();
                for (int i = 1; i < excelApp.ActiveWorkbook.Worksheets.Count + 1; i++)
                {
                    list.Add(excelApp.ActiveWorkbook.Worksheets[i].Name);
                }
                SheetNames.Set(context, list.ToArray());
            }
            catch (Exception e)
            {
                new CommonVariable().realaseProcessExit(excelApp);
                SharedObject.Instance.Output(SharedObject.enOutputType.Error, "EXCEL增加新工作表执行过程出错", e.Message);
            }
            m_Delegate = new runDelegate(Run);
            return(m_Delegate.BeginInvoke(callback, state));
        }