Exemplo n.º 1
0
        private void barButtonXlsx_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            SaveFileDialog saveFileDialog = new SaveFileDialog( );

            saveFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
            saveFileDialog.Filter           = "Archivo XLSX (*.xlsx)|*.xlsx";
            saveFileDialog.FilterIndex      = 1;
            saveFileDialog.FileName         = "Productos.xlsx";
            saveFileDialog.Title            = "Guardar como";
            saveFileDialog.RestoreDirectory = true;

            if (saveFileDialog.ShowDialog( ) == DialogResult.OK)
            {
                try
                {
                    StartExport( );

                    Cursor currentCursor = Cursor.Current;
                    Cursor.Current = Cursors.WaitCursor;
                    DevExpress.XtraPrinting.IPrintingSystem ps = DevExpress.XtraPrinting.PrintHelper.GetCurrentPS( );
                    ps.AfterChange += new DevExpress.XtraPrinting.ChangeEventHandler(Export_ProgressEx);

                    gridProductos.ExportToXlsx(saveFileDialog.FileName);

                    ps.AfterChange -= new DevExpress.XtraPrinting.ChangeEventHandler(Export_ProgressEx);
                    Cursor.Current  = currentCursor;

                    EndExport( );

                    Process.Start(saveFileDialog.FileName);
                    MessageBarValue = string.Empty;
                }
                catch (Exception ex)
                {
                    log.Error(ex.Message, ex);
                    MessageBarValue = " No se pudo guardar a la ubicación. " + ex.Message;
                }
                finally
                {
                    barItem.Caption = MessageBarValue;
                }
            }
        }
Exemplo n.º 2
0
        private void ExportToEx(String filename, string ext, BaseView exportView)
        {
            Cursor currentCursor = Cursor.Current;

            Cursor.Current = Cursors.WaitCursor;
            DevExpress.XtraPrinting.IPrintingSystem ps = DevExpress.XtraPrinting.PrintHelper.GetCurrentPS();
            if (ext == "rtf")
            {
                exportView.ExportToRtf(filename);
            }
            if (ext == "pdf")
            {
                exportView.ExportToPdf(filename);
            }
            if (ext == "mht")
            {
                exportView.ExportToMht(filename);
            }
            if (ext == "htm")
            {
                exportView.ExportToHtml(filename);
            }
            if (ext == "txt")
            {
                exportView.ExportToText(filename);
            }
            if (ext == "xls")
            {
                exportView.ExportToXls(filename);
            }
            if (ext == "xlsx")
            {
                exportView.ExportToXlsx(filename);
            }
            Cursor.Current = currentCursor;
        }