Exemple #1
0
        internal ExcelViewModel(Application excel)
        {
            Workbooks = new ObservableCollection <WorkbookViewModel>();

            this.excel = excel;
            ((AppEvents_Event)excel).NewWorkbook += AddWorkbook;
            excel.WorkbookOpen     += AddWorkbook;
            excel.WorkbookActivate += ActiveWorkbookChanged;
            excel.SheetActivate    += ActiveSheetActivate;

            var workbooks = excel.Workbooks;

            foreach (var workbook in workbooks)
            {
                if (workbook is Workbook book)
                {
                    var workbookViewModel = new WorkbookViewModel(book);
                    Workbooks.Add(workbookViewModel);
                }
            }
        }
Exemple #2
0
        private void UpdateWorksheets(WorkbookViewModel workbookViewModel)
        {
            var workbook   = workbookViewModel.Workbook;
            var worksheets = workbook.Worksheets;

            try
            {
                foreach (var worksheetViewModel in workbookViewModel.Worksheets)
                {
                    var worksheetIsOpen = false;
                    foreach (var sheet in worksheets)
                    {
                        if (sheet is Worksheet worksheet)
                        {
                            if (worksheet == worksheetViewModel.Worksheet)
                            {
                                worksheetIsOpen = true;
                                break;
                            }
                        }
                    }

                    if (worksheetIsOpen == false)
                    {
                        workbookViewModel.Worksheets.Remove(worksheetViewModel);
                        worksheetViewModel.UpdateDisplayProperties();
                        break;
                    }
                    else
                    {
                        worksheetViewModel.UpdateDisplayProperties();
                    }
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.Message);
            }
        }
Exemple #3
0
        private void AddWorkbook(Workbook newWorkbook)
        {
            var workbookViewModel = new WorkbookViewModel(newWorkbook);

            Workbooks.Add(workbookViewModel);
        }