接上篇 Dev中GridControl的GridView 基本样式设置
上图:
导出部分的代码:
1 /// <summary> 2 /// 导出excel 3 /// </summary> 4 /// <param name="gdvList"></param> 5 /// <param name="fileName"></param> 6 private void NewExportToXls(string fileName) 7 { 8 try 9 { 10 using (SaveFileDialog saveFileDialog = new SaveFileDialog()) 11 { 12 saveFileDialog.Title = "导出Excel"; 13 saveFileDialog.Filter = "Excel文件(*.xls)|*.xls"; 14 saveFileDialog.FileName = fileName; 15 saveFileDialog.DefaultExt = "xls"; 16 saveFileDialog.AddExtension = true; 17 saveFileDialog.RestoreDirectory = true; 18 19 DialogResult dialogResult = saveFileDialog.ShowDialog(); 20 if (dialogResult == DialogResult.OK) 21 { 22 //导出相关设置(已在GridViewConfig()中设置) Dev中GridControl的GridView 基本样式设置 随笔中的方法 23 //gdv.AppearancePrint.Row.TextOptions.WordWrap = DevExpress.Utils.WordWrap.Wrap; 24 //gdv.OptionsPrint.AutoWidth = false; 25 //gdv.AppearancePrint.Row.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center; 26 27 DevExpress.XtraPrinting.XlsExportOptionsEx op = new DevExpress.XtraPrinting.XlsExportOptionsEx(); 28 op.ExportType = DevExpress.Export.ExportType.WYSIWYG; 29 gdv.ExportToXls(saveFileDialog.FileName, op); 30 DevExpress.XtraEditors.XtraMessageBox.Show("保存成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); 31 } 32 }; 33 } 34 catch (Exception ex) 35 { 36 MessageBox.Show(ex.Message); 37 } 38 }
结束!