示例#1
0
        private static void OnExecuteExportToExcel(object sender, ExecutedRoutedEventArgs args)
        {
            var treeGrid       = args.Source as SfTreeGrid;
            var optionsettings = args.Parameter as ExcelExportingOptionsWrapper;

            if (treeGrid == null || optionsettings == null)
            {
                return;
            }

            try
            {
                var options = new TreeGridExcelExportingOptions();
                options.ExcelVersion          = ExcelVersion.Excel2016;
                options.ExportingEventHandler = ExportingHandler;
                if (!optionsettings.CanCustomizeStyle)
                {
                    options.CellsExportingEventHandler = CellExportingHandler;
                }
                else
                {
                    options.CellsExportingEventHandler = CustomizeCellExportingHandler;
                }

                var excelEngine = treeGrid.ExportToExcel(options);

                var workBook = excelEngine.Excel.Workbooks[0];
                SaveFile(workBook);
            }
            catch (Exception)
            {
            }
        }
示例#2
0
        public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            var options = new TreeGridExcelExportingOptions();

            options.AllowOutliningGroups = (bool)values[0];
            options.AllowIndentColumn    = (bool)values[1];
            options.IsGridLinesVisible   = (bool)values[2];
            options.CanExportHyperLink   = (bool)values[3];

            var value = (int)values[4];

            options.NodeExpandMode = (value == 0 ? NodeExpandMode.Default : (value == 1 ? NodeExpandMode.ExpandAll : NodeExpandMode.CollapseAll));
            isCutomized            = (bool)values[5];
            return(options);
        }
示例#3
0
        private static void OnExecuteExportToExcel(object sender, ExecutedRoutedEventArgs args)
        {
            var treeGrid       = args.Source as SfTreeGrid;
            var optionsettings = args.Parameter as ExcelExportingOptionsWrapper;

            if (treeGrid == null || optionsettings == null)
            {
                return;
            }

            try
            {
                var options = new TreeGridExcelExportingOptions();
                options.ExcelVersion          = ExcelVersion.Excel2016;
                options.ExportingEventHandler = ExportingHandler;
                options.AllowIndentColumn     = optionsettings.AllowIndentColumn;
                options.AllowOutliningGroups  = optionsettings.AllowOutlining;
                options.IsGridLinesVisible    = optionsettings.isgridLinesVisible;
                options.NodeExpandMode        = (NodeExpandMode)optionsettings.NodeExpandModeIndex;
                if (!optionsettings.CanCustomizeStyle)
                {
                    options.CellsExportingEventHandler = CellExportingHandler;
                }
                else
                {
                    options.CellsExportingEventHandler = CustomizeCellExportingHandler;
                }

                var excelEngine = treeGrid.ExportToExcel(options);

                var workBook = excelEngine.Excel.Workbooks[0];
                SaveFile(workBook);
            }
            catch (Exception)
            {
            }
        }
示例#4
0
        private async void OnExportToExcel(object sender, RoutedEventArgs e)
        {
            var options = new TreeGridExcelExportingOptions()
            {
                AllowOutliningGroups = (bool)AllowOutlining.IsChecked,
                AllowIndentColumn    = (bool)AllowIndentColumn.IsChecked,
                IsGridLinesVisible   = (bool)IsGridLinesVisible.IsChecked,
                CanExportHyperLink   = (bool)CanExportHyperLink.IsChecked,
                NodeExpandMode       = (nodeexpandMode.SelectedIndex == 0 ? NodeExpandMode.Default :
                                        (nodeexpandMode.SelectedIndex == 1 ? NodeExpandMode.ExpandAll : NodeExpandMode.CollapseAll)),
                ExcelVersion          = ExcelVersion.Excel2013,
                ExportingEventHandler = ExportingHandler
            };

            if ((bool)customizeColumns.IsChecked)
            {
                options.CellsExportingEventHandler = CustomizeCellExportingHandler;
            }

            excelEngine = new ExcelEngine();
            IWorkbook workBook = excelEngine.Excel.Workbooks.Create();

            treeGrid.ExportToExcel(workBook, options);

            var savePicker = new FileSavePicker
            {
                SuggestedStartLocation = PickerLocationId.DocumentsLibrary,
                SuggestedFileName      = "Sample"
            };

            if (workBook.Version == ExcelVersion.Excel97to2003)
            {
                savePicker.FileTypeChoices.Add("Excel File (.xls)", new List <string>()
                {
                    ".xls"
                });
            }
            else
            {
                savePicker.FileTypeChoices.Add("Excel File (.xlsx)", new List <string>()
                {
                    ".xlsx"
                });
            }
            var storageFile = await savePicker.PickSaveFileAsync();

            if (storageFile != null)
            {
                await workBook.SaveAsAsync(storageFile);

                options.CellsExportingEventHandler = null;
                options.ExportingEventHandler      = null;
                var msgDialog = new MessageDialog("Do you want to view the Document?", "File has been created successfully.");

                var yesCmd = new UICommand("Yes");
                var noCmd  = new UICommand("No");
                msgDialog.Commands.Add(yesCmd);
                msgDialog.Commands.Add(noCmd);
                var cmd = await msgDialog.ShowAsync();

                if (cmd == yesCmd)
                {
                    // Launch the saved file
                    bool success = await Launcher.LaunchFileAsync(storageFile);
                }
            }
        }