예제 #1
0
        private void btnTampil_Click(object sender, EventArgs e)
        {
            string           sql = "select*from users";
            DataTable        dt  = new DataTable();
            MySqlDataAdapter da  = new MySqlDataAdapter(sql, con);

            da.Fill(dt);
            gridControl1.DataSource = dt;

            SaveFileDialog dlg = new SaveFileDialog();

            dlg.Filter = "CSV File|*.csv|Pdf File|*.pdf";
            DialogResult answer = dlg.ShowDialog();
            string       savePath;

            if (answer == System.Windows.Forms.DialogResult.OK)
            {
                savePath = dlg.FileName;

                if (dlg.FilterIndex == 0)
                {
                    DevExpress.XtraPrinting.CsvExportOptions opt = new DevExpress.XtraPrinting.CsvExportOptions();
                    opt.Separator = ";";
                    gridControl1.ExportToCsv(savePath, opt);
                }

                if (dlg.FilterIndex == 1)
                {
                    gridControl1.ExportToPdf(savePath);
                }
            }
        }
예제 #2
0
        private static void OnExportToExcelClick(object sender, EventArgs e)
        {
            DXMenuItem item = sender as DXMenuItem;
            RowInfo info = item.Tag as RowInfo;
            var exportType = info.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) {
                        info.View.OptionsPrint.AutoWidth = false;
                        info.View.BestFitColumns();

                        FileStream fs = (FileStream)dialog1.OpenFile();
                        if (exportType == ViewExportType.CSV) {
                            DevExpress.XtraPrinting.CsvExportOptions opts = new DevExpress.XtraPrinting.CsvExportOptions();
                            info.View.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";
                            info.View.GridControl.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";
                            info.View.GridControl.ExportToXls(fs, opts);
                        }
                        fs.Close();
                    }

                }
            }
        }