C# DevExpress GridControl匯出表格【轉】

來源:互聯網
上載者:User

標籤:oid   ldo   class   csdn   rtt   exce   提示   string   article   

DevExpress的GridControl提供方便的資料匯出功能,可以方便的匯出Exce,PDF,Html頁面,world形式,無需寫額外的代碼,方便、快捷。

/// <summary>        /// 匯出表格 /// </summary> /// <param name="gridControl1"></param> public static void DevExpressGridControlExport(GridControl gridControl1) { using (var saveDialog = new SaveFileDialog()) { saveDialog.Filter = Resources.CommonFunction_DevExpressGridControlExport_Excel_97_2007檔案___xls_Excel_2010___xlsx_Excel__2003___xls____xls_Excel__2010____xlsx____xlsx__RichText_File___rtf____rtf__Pdf_File___pdf____pdf__Html_File___html____html; if (saveDialog.ShowDialog() == DialogResult.Cancel) return; var exportFilePath = saveDialog.FileName; var fileExtenstion = new FileInfo(exportFilePath).Extension; switch (fileExtenstion) { case ".xls": gridControl1.ExportToXls(exportFilePath); break; case ".xlsx": gridControl1.ExportToXlsx(exportFilePath); break; case ".rtf": gridControl1.ExportToRtf(exportFilePath); break; case ".pdf": gridControl1.ExportToPdf(exportFilePath); break; case ".html": gridControl1.ExportToHtml(exportFilePath); break; case ".mht": gridControl1.ExportToMht(exportFilePath); break; } if (File.Exists(exportFilePath)) { try { if (DialogResult.Yes == MessageBox.Show(Resources.CommonFunction_DevExpressGridControlExport_, Resources.CommonFunction_DevExpressGridControlExport_提示, MessageBoxButtons.YesNo)) { Process.Start(exportFilePath); } } catch { var msg = "The file could not be opened." + Environment.NewLine + Environment.NewLine + "Path: " + exportFilePath; MessageBox.Show(msg, Resources.CommonFunction_DevExpressGridControlExport_Error_, MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { var msg = "The file could not be saved." + Environment.NewLine + Environment.NewLine + "Path: " + exportFilePath; MessageBox.Show(msg, Resources.CommonFunction_DevExpressGridControlExport_Error_, MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
原文網址: 70212796

C# DevExpress GridControl匯出表格【轉】

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.