接上篇 Dev中GridControl的GridView 基本样式设置
上图:
导出部分的代码:
/// <summary>
/// 导出excel
/// </summary>
/// <param name="gdvList"></param>
/// <param name="fileName"></param>
private void NewExportToXls(string fileName)
{
try
{
using (SaveFileDialog saveFileDialog = new SaveFileDialog())
{
saveFileDialog.Title = "导出Excel";
saveFileDialog.Filter = "Excel文件(*.xls)|*.xls";
saveFileDialog.FileName = fileName;
saveFileDialog.DefaultExt = "xls";
saveFileDialog.AddExtension = true;
saveFileDialog.RestoreDirectory = true; DialogResult dialogResult = saveFileDialog.ShowDialog();
if (dialogResult == DialogResult.OK)
{
//导出相关设置(已在GridViewConfig()中设置) Dev中GridControl的GridView 基本样式设置 随笔中的方法
//gdv.AppearancePrint.Row.TextOptions.WordWrap = DevExpress.Utils.WordWrap.Wrap;
//gdv.OptionsPrint.AutoWidth = false;
//gdv.AppearancePrint.Row.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center; DevExpress.XtraPrinting.XlsExportOptionsEx op = new DevExpress.XtraPrinting.XlsExportOptionsEx();
op.ExportType = DevExpress.Export.ExportType.WYSIWYG;
gdv.ExportToXls(saveFileDialog.FileName, op);
DevExpress.XtraEditors.XtraMessageBox.Show("保存成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
};
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
结束!