DevExpress中GridView Excel下载

  DevExpress中GridView提供了许多Excel下载的方法,如gridView.ExportToExcelOld(sfdExcelDown.FileName); 在修改Bug时,遇到这样问题,ExportToExcelOld方法在第一次下载时,Excel样式正常,但覆盖第一次下载的Excel后,Excel的样式将发生改变,在做上传Excel操作时,引起错误!!

下面没有直接使用GridView的方法,调用该方法,覆盖下载的Excel后,样式不会改变:

 1         private void ExcelSampleDown(GridView gridView)
 2         {
 3 
 4             SaveFileDialog sfdExcelDown = new SaveFileDialog();
 5 
 6             System.IO.DriveInfo[] allDrives = System.IO.DriveInfo.GetDrives();
 7             string disk = "";
 8             foreach (System.IO.DriveInfo d in allDrives)
 9             {
10                 if (d.Name.Contains("Client") || d.DriveType == System.IO.DriveType.Network)
11                 {
12                     disk = d.Name;
13                     break;
14                 }
15             }
16 
17             sfdExcelDown.InitialDirectory = disk;
18 
19             sfdExcelDown.Filter = "Microsoft Excel|*.xls";
20             DialogResult result = sfdExcelDown.ShowDialog();
21             if (result != DialogResult.OK) return;
22 
23             if (!FormUtil.CheckFileNameRegex(System.IO.Path.GetFileName(sfdExcelDown.FileName)))
24             {
25                 FormUtil.ShowMessage(FormUtil.MessageType.ALERT, FormUtil.MessageLevel.WANNING, "COM095");//多语言 文件路径不对
26                 return;
27             }
28 
29             if (FileStatus.FileIsOpen(sfdExcelDown.FileName) == 1)
30             {
31                 FormUtil.ShowMessage(FormUtil.MessageType.ALERT, FormUtil.MessageLevel.INFORMATION, "CEM133");//多语言 文件已打开,请关闭文件,重新操作
32                 return;
33             }
34 
35             DevExpress.XtraExport.ExportXlsProvider provider = new DevExpress.XtraExport.ExportXlsProvider(sfdExcelDown.FileName);
36             Cursor currentCursor = Cursor.Current;
37             Cursor.Current = Cursors.WaitCursor;
38             this.FindForm().Refresh();
39             DevExpress.XtraGrid.Export.BaseExportLink link = gridView.CreateExportLink(provider);
40             (link as DevExpress.XtraGrid.Export.GridViewExportLink).ExpandAll = false;
41             link.ExportTo(true);
42             provider.Dispose();
43             Cursor.Current = currentCursor;
44 
45             //gridView.ExportToExcelOld(sfdExcelDown.FileName);DevExpress中的方法,该方法在二次覆盖文件时,会改变Excel样式
46         }


虽然问题解决了,但不清楚gridView.ExportToExcelOld(sfdExcelDown.FileName);到底进行了什么操作从而引起覆盖时错误???

下载Excel正常情况:

 

覆盖后不正常Excel,标题背景样式和边界样式没有了:

 

posted @ 2013-07-16 13:33  bkyshj  阅读(769)  评论(0编辑  收藏  举报