Dev控制項GridControl和TreeList的數據導出操作

来源:http://www.cnblogs.com/XiaoZone/archive/2017/11/17/7851879.html
-Advertisement-
Play Games

DEV控制項GridControl和TreeList的數據導出操作 ...


導出pdf格式出現亂碼時可以在main 方法中添加如下代碼: DevExpress.Utils.AppearanceObject.DefaultFont = new System.Drawing.Font("宋體", 9);
  1 /// <summary>
  2     /// 數據導出
  3     /// </summary>
  4     public class DataExport
  5     {
  6         /// <summary>
  7         /// 導出GridConrol中的數據
  8         /// </summary>
  9         /// <param name="gridControl"></param>
 10         public static void GridControlExport(GridControl gridControl)
 11         {
 12             using (SaveFileDialog saveDialog = new SaveFileDialog())
 13             {
 14                 saveDialog.Filter = "Excel (2003)(.xls)|*.xls|Excel (2010) (.xlsx)|*.xlsx |RichText File (.rtf)|*.rtf |Pdf File (.pdf)|*.pdf |Html File (.html)|*.html";
 15                 if (saveDialog.ShowDialog() != DialogResult.Cancel)
 16                 {
 17                     string exportFilePath = saveDialog.FileName;
 18                     string fileExtenstion = new FileInfo(exportFilePath).Extension;
 19 
 20                     switch (fileExtenstion)
 21                     {
 22                         case ".xls":
 23                             gridControl.ExportToXls(exportFilePath);
 24                             break;
 25                         case ".xlsx":
 26                             gridControl.ExportToXlsx(exportFilePath);
 27                             break;
 28                         case ".rtf":
 29                             gridControl.ExportToRtf(exportFilePath);
 30                             break;
 31                         case ".pdf":
 32                             gridControl.ExportToPdf(exportFilePath);
 33                             break;
 34                         case ".html":
 35                             gridControl.ExportToHtml(exportFilePath);
 36                             break;
 37                         case ".mht":
 38                             gridControl.ExportToMht(exportFilePath);
 39                             break;
 40                         case ".csv":
 41                             gridControl.ExportToCsv(exportFilePath);
 42                             break;
 43                         default:
 44                             break;
 45                     }
 46 
 47                     if (File.Exists(exportFilePath))
 48                     {
 49                         try
 50                         {
 51                             if (DialogResult.Yes == MessageBox.Show("文件已成功導出,是否打開文件?", "提示", MessageBoxButtons.YesNo))
 52                             {
 53                                 System.Diagnostics.Process.Start(exportFilePath);
 54                             }
 55                         }
 56                         catch
 57                         {
 58                             String msg = "The file could not be opened." + Environment.NewLine + Environment.NewLine + "Path: " + exportFilePath;
 59                             MessageBox.Show(msg, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
 60                         }
 61                     }
 62                     else
 63                     {
 64                         String msg = "The file could not be saved." + Environment.NewLine + Environment.NewLine + "Path: " + exportFilePath;
 65                         MessageBox.Show(msg, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
 66                     }
 67                 }
 68             }
 69         }
 70         /// <summary>
 71         /// 導出TreeList中的數據
 72         /// </summary>
 73         /// <param name="treeList"></param>
 74         public static void TreeListExport(TreeList treeList)
 75         {
 76             using (SaveFileDialog saveDialog = new SaveFileDialog())
 77             {
 78                 saveDialog.Filter = "Excel (2003)(.xls)|*.xls|Excel (2010) (.xlsx)|*.xlsx |RichText File (.rtf)|*.rtf |Pdf File (.pdf)|*.pdf |Html File (.html)|*.html";
 79                 if (saveDialog.ShowDialog() != DialogResult.Cancel)
 80                 {
 81                     string exportFilePath = saveDialog.FileName;
 82                     string fileExtenstion = new FileInfo(exportFilePath).Extension;
 83 
 84                     switch (fileExtenstion)
 85                     {
 86                         case ".xls":
 87                             treeList.ExportToXls(exportFilePath);
 88                             break;
 89                         case ".xlsx":
 90                             treeList.ExportToXlsx(exportFilePath);
 91                             break;
 92                         case ".rtf":
 93                             treeList.ExportToRtf(exportFilePath);
 94                             break;
 95                         case ".pdf":
 96                             treeList.ExportToPdf(exportFilePath);
 97                             break;
 98                         case ".csv":
 99                             treeList.ExportToCsv(exportFilePath);
100                             break;
101                         
102                         default:
103                             break;
104                     }
105 
106                     if (File.Exists(exportFilePath))
107                     {
108                         try
109                         {
110                             if (DialogResult.Yes == MessageBox.Show("文件已成功導出,是否打開文件?", "提示", MessageBoxButtons.YesNo))
111                             {
112                                 System.Diagnostics.Process.Start(exportFilePath);
113                             }
114                         }
115                         catch
116                         {
117                             String msg = "The file could not be opened." + Environment.NewLine + Environment.NewLine + "Path: " + exportFilePath;
118                             MessageBox.Show(msg, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
119                         }
120                     }
121                     else
122                     {
123                         String msg = "The file could not be saved." + Environment.NewLine + Environment.NewLine + "Path: " + exportFilePath;
124                         MessageBox.Show(msg, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
125                     }
126                 }
127             }
128         }
129     }
View Code

 


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 1.1.1 chrony簡介 Chrony是一個開源的自由軟體,它能保持系統時鐘與時鐘伺服器(NTP)同步,讓時間保持精確。 它由兩個程式組成:chronyd和chronyc。 chronyd是一個後臺運行的守護進程,用於調整內核中運行的系統時鐘和時鐘伺服器同步。它確定電腦增減時間的比率,並對此進 ...
  • 1、安裝Office2007以上版本。(如安裝的是Office2007需安裝SaveAsPDFandXPS.exe組件) 2、確認網站在IIS內使用的登錄用戶。(如圖所示用戶為IUSR,下麵操作以此用戶為例) 3、打開運行視窗,執行comexp.msc -32 ,打開32位的組件服務。 4、分別設置 ...
  • arch/x86/boot/header.S --> _start --> calll main arch/x86/boot/main.c --> main -- > go_to_protected_mode arch/x86/boot/pm.c --> go_to_protected_mode - ...
  • [20171115]ZEROCONF ROUTE.txt--//如果你檢查linux伺服器的網路配置,就可以發現如下一條路由:# route -n | egrep "169.254|Destination"Destination Gateway Genmask Flags Metric Ref Us ...
  • 總項目流程圖,詳見http://www.cnblogs.com/along21/p/7435612.html 實驗一:實現反向代理負載均衡且動靜分離 1、環境準備: 機器名稱 IP配置 服務角色 備註 nginx VIP:172.17.11.11 反向代理伺服器 開啟代理功能 設置監控,調度 rs0 ...
  • 一.序言 本資料是Trevor Martin編寫的《The Designers Guide to the Cortex-M Processor Family》的摘要,並得到Elsevier的再版許可。查詢更多細節,請到本資料尾部進階章節。 本資料著力於介紹RTX,RTX可運行在基於Cortex-M構 ...
  • 背景: 一段明顯的字元串,可能潛伏著看不見 的 幽靈字元。 某些字元 比較常見、常用,比如: \r \n \t 但是,有些 幽靈字元(保守估計 >200~1000個),不僅不常見,而且基本沒價值。 這些幽靈字元,潛伏在 正常字元串中,有的偽裝成空格符,有的直接隱形。 當你要 處理字元串時,這些幽靈字 ...
  • 在使用由Angular,React,Vue等應用程式框架構建的客戶端應用程式時,您總是會處理HTML5客戶端路由,它將完全在瀏覽器中處理到頁面和組件的客戶端路由。幾乎完全在瀏覽器中... HTML5客戶端路由在客戶端上工作的很好,但是當深入鏈接到一個站點或在瀏覽器中按刷新時,客戶端路由有一個惡習,變 ...
一周排行
    -Advertisement-
    Play Games
  • 前言 在我們開發過程中基本上不可或缺的用到一些敏感機密數據,比如SQL伺服器的連接串或者是OAuth2的Secret等,這些敏感數據在代碼中是不太安全的,我們不應該在源代碼中存儲密碼和其他的敏感數據,一種推薦的方式是通過Asp.Net Core的機密管理器。 機密管理器 在 ASP.NET Core ...
  • 新改進提供的Taurus Rpc 功能,可以簡化微服務間的調用,同時可以不用再手動輸出模塊名稱,或調用路徑,包括負載均衡,這一切,由框架實現並提供了。新的Taurus Rpc 功能,將使得服務間的調用,更加輕鬆、簡約、高效。 ...
  • 順序棧的介面程式 目錄順序棧的介面程式頭文件創建順序棧入棧出棧利用棧將10進位轉16進位數驗證 頭文件 #include <stdio.h> #include <stdbool.h> #include <stdlib.h> 創建順序棧 // 指的是順序棧中的元素的數據類型,用戶可以根據需要進行修改 ...
  • 前言 整理這個官方翻譯的系列,原因是網上大部分的 tomcat 版本比較舊,此版本為 v11 最新的版本。 開源項目 從零手寫實現 tomcat minicat 別稱【嗅虎】心有猛虎,輕嗅薔薇。 系列文章 web server apache tomcat11-01-官方文檔入門介紹 web serv ...
  • C總結與剖析:關鍵字篇 -- <<C語言深度解剖>> 目錄C總結與剖析:關鍵字篇 -- <<C語言深度解剖>>程式的本質:二進位文件變數1.變數:記憶體上的某個位置開闢的空間2.變數的初始化3.為什麼要有變數4.局部變數與全局變數5.變數的大小由類型決定6.任何一個變數,記憶體賦值都是從低地址開始往高地 ...
  • 如果讓你來做一個有狀態流式應用的故障恢復,你會如何來做呢? 單機和多機會遇到什麼不同的問題? Flink Checkpoint 是做什麼用的?原理是什麼? ...
  • C++ 多級繼承 多級繼承是一種面向對象編程(OOP)特性,允許一個類從多個基類繼承屬性和方法。它使代碼更易於組織和維護,並促進代碼重用。 多級繼承的語法 在 C++ 中,使用 : 符號來指定繼承關係。多級繼承的語法如下: class DerivedClass : public BaseClass1 ...
  • 前言 什麼是SpringCloud? Spring Cloud 是一系列框架的有序集合,它利用 Spring Boot 的開發便利性簡化了分散式系統的開發,比如服務註冊、服務發現、網關、路由、鏈路追蹤等。Spring Cloud 並不是重覆造輪子,而是將市面上開發得比較好的模塊集成進去,進行封裝,從 ...
  • class_template 類模板和函數模板的定義和使用類似,我們已經進行了介紹。有時,有兩個或多個類,其功能是相同的,僅僅是數據類型不同。類模板用於實現類所需數據的類型參數化 template<class NameType, class AgeType> class Person { publi ...
  • 目錄system v IPC簡介共用記憶體需要用到的函數介面shmget函數--獲取對象IDshmat函數--獲得映射空間shmctl函數--釋放資源共用記憶體實現思路註意 system v IPC簡介 消息隊列、共用記憶體和信號量統稱為system v IPC(進程間通信機制),V是羅馬數字5,是UNI ...