Exemple #1
0
        // Imports a range from workbook chosen by end-user. Assumes table starts at cell A1 on the first worksheet.
        public static void Import(IVisualCollection collection)
        {
            _collection = collection;

            Dispatchers.Main.BeginInvoke(() =>
            {
                OpenFileDialog dialog = new OpenFileDialog();
                dialog.Multiselect    = false;
                dialog.Filter         = "Excel Documents(*.xls;*.xlsx;*.csv)|*.xls;*.xlsx;*.csv|All files (*.*)|*.*";
                if (dialog.ShowDialog() == true)
                {
                    FileInfo f = dialog.File;
                    try
                    {
                        ExcelHelper excel = new ExcelHelper();
                        excel.OpenWorkbook(f.FullName);
                        _excelDocRange = excel.UsedRange(1, 1);
                        excel.Dispose();

                        List <FieldDefinition> tablePropertyChoices = GetTablePropertyChoices();

                        _columnMappings  = new List <ColumnMapping>();
                        Int32 numColumns = _excelDocRange.GetLength(1);
                        for (var i = 0; i <= numColumns - 1; i++)
                        {
                            _columnMappings.Add(new ColumnMapping(_excelDocRange[0, i], tablePropertyChoices));
                        }

                        ColumnMapper columnMapperContent      = new ColumnMapper();
                        columnMapperContent.OfficeColumn.Text = "Excel Column";
                        ScreenChildWindow columnMapperWindow  = new ScreenChildWindow();
                        columnMapperContent.DataContext       = _columnMappings;
                        columnMapperWindow.Closed            += OnMappingDialogClosed;

                        //set parent to current screen
                        IServiceProxy sdkProxy   = VsExportProviderService.GetExportedValue <IServiceProxy>();
                        columnMapperWindow.Owner = (Control)sdkProxy.ScreenViewService.GetScreenView(_collection.Screen).RootUI;
                        columnMapperWindow.Show(_collection.Screen, columnMapperContent);
                    }
                    catch (SecurityException ex)
                    {
                        collection.Screen.Details.Dispatcher.BeginInvoke(() => { _collection.Screen.ShowMessageBox("Error: Silverlight Security error. Could not load Excel document. Make sure the document is in your 'Documents' directory."); });
                    }
                    catch (COMException comEx)
                    {
                        _collection.Screen.Details.Dispatcher.BeginInvoke(() => { _collection.Screen.ShowMessageBox("Error: Could not open this file.  It may not be a valid Excel document."); });
                    }
                }
            });
        }
Exemple #2
0
        // Imports a range starting at the location specified by workbook, worksheet, and range.
        // Workbook should be the full path to the workbook.
        public static void Import(IVisualCollection collection, string Workbook, string Worksheet, string Range)
        {
            _collection = collection;

            Dispatchers.Main.BeginInvoke(() =>
            {
                ExcelHelper xlProxy = new ExcelHelper();
                dynamic wb          = null;
                dynamic ws          = null;
                dynamic rg          = null;

                wb = xlProxy.Excel.Workbooks.Open(Workbook);
                if ((wb != null))
                {
                    ws = wb.Worksheets(Worksheet);
                    if ((ws != null))
                    {
                        rg             = ws.Range(Range);
                        _excelDocRange = ConvertToArray(rg);

                        List <FieldDefinition> tablePropertyChoices = GetTablePropertyChoices();

                        _columnMappings  = new List <ColumnMapping>();
                        Int32 numColumns = _excelDocRange.GetLength(1);
                        for (var i = 0; i <= numColumns - 1; i++)
                        {
                            _columnMappings.Add(new ColumnMapping(_excelDocRange[0, i], tablePropertyChoices));
                        }

                        ColumnMapper columnMapperContent      = new ColumnMapper();
                        columnMapperContent.OfficeColumn.Text = "Excel Column";
                        ScreenChildWindow columnMapperWindow  = new ScreenChildWindow();
                        columnMapperContent.DataContext       = _columnMappings;
                        columnMapperWindow.Closed            += OnMappingDialogClosed;

                        //set parent to current screen
                        IServiceProxy sdkProxy   = VsExportProviderService.GetExportedValue <IServiceProxy>();
                        columnMapperWindow.Owner = (Control)sdkProxy.ScreenViewService.GetScreenView(_collection.Screen).RootUI;
                        columnMapperWindow.Show(_collection.Screen, columnMapperContent);
                    }
                }

                rg = null;
                ws = null;
                wb.Close(false);
                wb = null;
                xlProxy.Dispose();
            });
        }
Exemple #3
0
        private static void DisplayErrors(List <string> errorList)
        {
            Dispatchers.Main.BeginInvoke(() =>
            {
                //Display some sort of dialog indicating that errors occurred
                IServiceProxy sdkProxy        = VsExportProviderService.GetExportedValue <IServiceProxy>();
                ErrorList errorDialog         = new ErrorList();
                ScreenChildWindow errorWindow = new ScreenChildWindow();
                errorDialog.DataContext       = errorList;
                errorWindow.DataContext       = errorList;
                errorWindow.Owner             = (Control)sdkProxy.ScreenViewService.GetScreenView(_collection.Screen).RootUI;

                errorWindow.Closed += OnErroDialogClosed;
                errorWindow.Show(_collection.Screen, errorDialog);
            });
        }