此方法不适合12.1版本
private
void
barExport_ItemClick(
object
sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
SaveFileDialog saveFileDialog =
new
SaveFileDialog();
saveFileDialog.Title =
"导出Excel"
;
saveFileDialog.Filter =
"Excel文件(*.xls)|*.xls"
;
DialogResult dialogResult = saveFileDialog.ShowDialog(
this
);
if
(dialogResult == DialogResult.OK)
{
DevExpress.XtraPrinting.XlsExportOptions options =
new
DevExpress.XtraPrinting.XlsExportOptions();
gridControl1.ExportToXls(saveFileDialog.FileName);
DevExpress.XtraEditors.XtraMessageBox.Show(
"保存成功!"
,
"提示"
, MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
12.1版本导出
TableView dg = obj as TableView;
if (dg != null)
{
System.Windows.Forms.SaveFileDialog saveFileDialog = new System.Windows.Forms.SaveFileDialog();
saveFileDialog.DefaultExt = "*.xls";
saveFileDialog.AddExtension = true;
saveFileDialog.Filter = "Excel 文件|*.xls";
saveFileDialog.OverwritePrompt = true;
saveFileDialog.CheckPathExists = true;
if (saveFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK && saveFileDialog.FileName != null)
{
string fileName = saveFileDialog.FileName;//文件名字
DevExpress.XtraPrinting.XlsExportOptions options = new DevExpress.XtraPrinting.XlsExportOptions(DevExpress.XtraPrinting.TextExportMode.Value);
dg.ExportToXls(fileName, options);
MessageBox.Show("报表导出成功!", "系统提示");
}
}