示例#1
0
 public RowInfo(GridView view, int rowHandle, ViewExportType exportType)
 {
     this.RowHandle = rowHandle;
     this.View = view;
     this.ExportType = exportType;
 }
示例#2
0
            public void Export(ViewExportType exportType)
            {
                SaveFileDialog dialog1 = new SaveFileDialog();
                if (exportType == ViewExportType.Excel2003)
                    dialog1.Filter = "Excel Workbook (*.xls)|*.xls";
                else if (exportType == ViewExportType.Excel2007)
                    dialog1.Filter = "Excel Workbook (*.xslx)|*.xlsx";
                else if (exportType == ViewExportType.CSV)
                    dialog1.Filter = "CSV (Comma Delimited) (*.csv)|*.csv";

                dialog1.Title = "Save As";
                dialog1.CheckPathExists = true;
                dialog1.CheckFileExists = false;
                if (dialog1.ShowDialog() == DialogResult.OK) {
                    if (dialog1.FileName != "") {
                        if (dialog1.FilterIndex == 1) {
                            gridView1.OptionsPrint.AutoWidth = false;
                            gridView1.BestFitColumns();

                            FileStream fs = (FileStream)dialog1.OpenFile();
                            if (exportType == ViewExportType.CSV) {
                                DevExpress.XtraPrinting.CsvExportOptions opts = new DevExpress.XtraPrinting.CsvExportOptions();
                                gridView1.Export(DevExpress.XtraPrinting.ExportTarget.Csv, fs, opts);
                            }
                            else if (exportType == ViewExportType.Excel2007) {
                                DevExpress.XtraPrinting.XlsxExportOptions opts = new DevExpress.XtraPrinting.XlsxExportOptions();
                                opts.ExportMode = DevExpress.XtraPrinting.XlsxExportMode.SingleFile;
                                opts.SheetName = "Sheet1";
                                gridControl1.ExportToXlsx(fs, opts);
                            }
                            else if (exportType == ViewExportType.Excel2003) {
                                DevExpress.XtraPrinting.XlsExportOptions opts = new DevExpress.XtraPrinting.XlsExportOptions();
                                opts.ExportMode = DevExpress.XtraPrinting.XlsExportMode.SingleFile;
                                opts.SheetName = "Sheet1";
                                gridControl1.ExportToXls(fs, opts);
                            }
                            fs.Close();
                        }
                    }
                }
            }