DevExpress中GridView Excel下载

时间:2024-01-15 16:22:26

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

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

         private void ExcelSampleDown(GridView gridView)
{ SaveFileDialog sfdExcelDown = new SaveFileDialog(); System.IO.DriveInfo[] allDrives = System.IO.DriveInfo.GetDrives();
string disk = "";
foreach (System.IO.DriveInfo d in allDrives)
{
if (d.Name.Contains("Client") || d.DriveType == System.IO.DriveType.Network)
{
disk = d.Name;
break;
}
} sfdExcelDown.InitialDirectory = disk; sfdExcelDown.Filter = "Microsoft Excel|*.xls";
DialogResult result = sfdExcelDown.ShowDialog();
if (result != DialogResult.OK) return; if (!FormUtil.CheckFileNameRegex(System.IO.Path.GetFileName(sfdExcelDown.FileName)))
{
FormUtil.ShowMessage(FormUtil.MessageType.ALERT, FormUtil.MessageLevel.WANNING, "COM095");//多语言 文件路径不对
return;
} if (FileStatus.FileIsOpen(sfdExcelDown.FileName) == )
{
FormUtil.ShowMessage(FormUtil.MessageType.ALERT, FormUtil.MessageLevel.INFORMATION, "CEM133");//多语言 文件已打开,请关闭文件,重新操作
return;
} DevExpress.XtraExport.ExportXlsProvider provider = new DevExpress.XtraExport.ExportXlsProvider(sfdExcelDown.FileName);
Cursor currentCursor = Cursor.Current;
Cursor.Current = Cursors.WaitCursor;
this.FindForm().Refresh();
DevExpress.XtraGrid.Export.BaseExportLink link = gridView.CreateExportLink(provider);
(link as DevExpress.XtraGrid.Export.GridViewExportLink).ExpandAll = false;
link.ExportTo(true);
provider.Dispose();
Cursor.Current = currentCursor; //gridView.ExportToExcelOld(sfdExcelDown.FileName);DevExpress中的方法,该方法在二次覆盖文件时,会改变Excel样式
}

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

下载Excel正常情况:

DevExpress中GridView Excel下载

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

DevExpress中GridView Excel下载