Ejemplo n.º 1
0
        private void ExportaXLS_Click(object sender, RoutedEventArgs e)
        {
            var options = new Syncfusion.UI.Xaml.Grid.Converter.ExcelExportingOptions();

            options.ExcelVersion = ExcelVersion.Excel2013;
            options.CellsExportingEventHandler = CellExportingHandler;

            var excelEngine = GridKardex.ExportToExcel(GridKardex.View, options);
            var workBook    = excelEngine.Excel.Workbooks[0];



            SaveFileDialog sfd = new SaveFileDialog
            {
                FilterIndex = 2,
                Filter      = "Excel 97 to 2003 Files(*.xls)|*.xls|Excel 2007 to 2010 Files(*.xlsx)|*.xlsx|Excel 2013 File(*.xlsx)|*.xlsx"
            };



            if (sfd.ShowDialog() == true)
            {
                using (Stream stream = sfd.OpenFile())
                {
                    if (sfd.FilterIndex == 1)
                    {
                        workBook.Version = ExcelVersion.Excel97to2003;
                    }
                    else if (sfd.FilterIndex == 2)
                    {
                        workBook.Version = ExcelVersion.Excel2010;
                    }
                    else
                    {
                        workBook.Version = ExcelVersion.Excel2013;
                    }
                    workBook.SaveAs(stream);
                }

                //Message box confirmation to view the created workbook.
                if (MessageBox.Show("Usted quiere abrir el archivo en excel?", "Ver archvo",
                                    MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.Yes)
                {
                    //Launching the Excel file using the default Application.[MS Excel Or Free ExcelViewer]
                    System.Diagnostics.Process.Start(sfd.FileName);
                }
            }
        }
Ejemplo n.º 2
0
        private void ExportaXLS_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                var options = new Syncfusion.UI.Xaml.Grid.Converter.ExcelExportingOptions();
                options.ExcelVersion = ExcelVersion.Excel2013;

                //options.ExcludeColumns.Add("idreg");
                //options.ExcludeColumns.Add("cod_trn");
                //options.ExcludeColumns.Add("nom_trn");
                //options.ExcludeColumns.Add("num_trn");
                //options.ExcludeColumns.Add("fec_trn");
                //options.ExcludeColumns.Add("bod_tra");
                //options.ExcludeColumns.Add("ent_uni");
                //options.ExcludeColumns.Add("ent_cost");
                //options.ExcludeColumns.Add("ent_ctotal");
                //options.ExcludeColumns.Add("sal_uni");
                //options.ExcludeColumns.Add("sal_cost");
                //options.ExcludeColumns.Add("sal_ctotal");
                //options.ExcludeColumns.Add("saldo_uni");
                //options.ExcludeColumns.Add("saldo_cost");
                //options.ExcludeColumns.Add("saldo_ctotal");



                var excelEngine = GridKardex.ExportToExcel(GridKardex.View, options);
                var workBook    = excelEngine.Excel.Workbooks[0];


                SaveFileDialog sfd = new SaveFileDialog
                {
                    FilterIndex = 2,
                    Filter      = "Excel 97 to 2003 Files(*.xls)|*.xls|Excel 2007 to 2010 Files(*.xlsx)|*.xlsx|Excel 2013 File(*.xlsx)|*.xlsx"
                };
                if (sfd.ShowDialog() == true)
                {
                    using (Stream stream = sfd.OpenFile())
                    {
                        if (sfd.FilterIndex == 1)
                        {
                            workBook.Version = ExcelVersion.Excel97to2003;
                        }
                        else if (sfd.FilterIndex == 2)
                        {
                            workBook.Version = ExcelVersion.Excel2010;
                        }
                        else
                        {
                            workBook.Version = ExcelVersion.Excel2013;
                        }
                        workBook.SaveAs(stream);
                    }
                    //Message box confirmation to view the created workbook.
                    if (MessageBox.Show("Usted quiere abrir el archivo en excel?", "Ver archvo", MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.Yes)
                    {
                        //Launching the Excel file using the default Application.[MS Excel Or Free ExcelViewer]
                        System.Diagnostics.Process.Start(sfd.FileName);
                    }
                }
            }
            catch (Exception w)
            {
                MessageBox.Show("error al exportar:" + w);
            }
        }