分享下DevExpress里GridControl自带导出excel功能
By
admin
at 2022-11-09 • 0人收藏 • 639人看过
private void barbtnExport_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { SaveFileDialog fileDialog = new SaveFileDialog(); //fileDialog.Title = "结算";//设置打印表头 //fileDialog.FileName = fileDialog.Title + DateTime.Now.ToString("yyyyMMdd");//设置文件保存名称 fileDialog.Filter = "Excel文件(*.xlsx)|*.xlsx";//设置文件保存格式显示 DialogResult dialogResult = fileDialog.ShowDialog(this); if (dialogResult == DialogResult.OK) { DevExpress.XtraPrinting.XlsExportOptionsEx options = new DevExpress.XtraPrinting.XlsExportOptionsEx(); options.TextExportMode = TextExportMode.Text; options.RawDataMode = false; //options.TextExportMode = TextExportMode.Value;//设置导出模式为数值 options.TextExportMode = TextExportMode.Text;//设置导出模式为文本 options.ShowGridLines = true; options.ExportType = ExportType.WYSIWYG; gridView1.OptionsPrint.PrintHeader = true;//不显列头 gridView1.OptionsPrint.AutoWidth = true;//不自动列宽 gridView1.OptionsPrint.EnableAppearanceEvenRow = true; gridView1.AppearancePrint.HeaderPanel.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center;//表头居中 gridControl1.ExportToXlsx(fileDialog.FileName);//导出Excel DevExpress.XtraEditors.XtraMessageBox.Show("保存成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); //提示 } }
登录后方可回帖