1 SaveFileDialog fileDialog = new SaveFileDialog();
2 fileDialog.Title = "导出Excel";
3 fileDialog.Filter = "Excel文件(*.xls)|*.xls";
4 DialogResult dialogResult = fileDialog.ShowDialog(this);
5 if (dialogResult == DialogResult.OK)
6 {
7 try
8 {
9 DevExpress.XtraPrinting.XlsExportOptions options = new DevExpress.XtraPrinting.XlsExportOptions();
10 gridControl1.ExportToXls(fileDialog.FileName);
11 DevExpress.XtraEditors.XtraMessageBox.Show("保存成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
12 }
13 catch (Exception ex)
14 {
15
16 if (ex.Message.Contains("正由另一进程使用"))
17 {
18 DevExpress.XtraEditors.XtraMessageBox.Show("数据导出失败!文件正由另一个程序占用!", "提示");
19 }
20 else
21 DevExpress.XtraEditors.XtraMessageBox.Show("数据导出失败!数据量过大,请分别统计再导出!", "提示");
22 }
23
24 }
注:导出excel列宽度问题