zoukankan      html  css  js  c++  java
  • 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,标题背景样式和边界样式没有了:

  • 相关阅读:
    1-1 10:超级玛丽游戏
    1-1 09:字符菱形
    【Lucene4.8教程之四】分析
    【Lucene4.8教程之六】QueryParser与Query子类:如何生成Query对象
    【Lucene4.8教程之三】搜索
    Java路径问题最终解决方案—可定位所有资源的相对路径寻址
    java.util.logging.Logger基础教程
    【Lucene4.8教程之二】索引
    【Lucene4.8教程之一】使用Lucene4.8进行索引及搜索的基本操作
    重要学习参考资料
  • 原文地址:https://www.cnblogs.com/mybky/p/3193171.html
Copyright © 2011-2022 走看看