zoukankan      html  css  js  c++  java
  • Devexpress GridControl.Export 导出

    private void mnuExportTable_ItemClick_1(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
    {
    using (SaveFileDialog saveDialog = new SaveFileDialog())
    {
    saveDialog.Filter = "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)
    {
    string exportFilePath = saveDialog.FileName;
    string fileExtenstion = new FileInfo(exportFilePath).Extension;

    switch (fileExtenstion)
    {
    case ".xls":
    gridControl.ExportToXls(exportFilePath);
    break;
    case ".xlsx":
    gridControl.ExportToXlsx(exportFilePath);
    break;
    case ".rtf":
    gridControl.ExportToRtf(exportFilePath);
    break;
    case ".pdf":
    gridControl.ExportToPdf(exportFilePath);
    break;
    case ".html":
    gridControl.ExportToHtml(exportFilePath);
    break;
    case ".mht":
    gridControl.ExportToMht(exportFilePath);
    break;
    default:
    break;
    }

    if (File.Exists(exportFilePath))
    {
    try
    {
    //Try to open the file and let windows decide how to open it.
    System.Diagnostics.Process.Start(exportFilePath);
    }
    catch
    {
    String msg = "The file could not be opened." + Environment.NewLine + Environment.NewLine + "Path: " + exportFilePath;
    MessageBox.Show(msg, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
    }
    }
    else
    {
    String msg = "The file could not be saved." + Environment.NewLine + Environment.NewLine + "Path: " + exportFilePath;
    MessageBox.Show(msg, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
    }
    }
    }
    }

  • 相关阅读:
    .NET题目(收集来自网络)
    c#反射
    c#泛型
    asp.net core 下载文件,上传excel文件
    remote: HTTP Basic: Access denied fatal: Authentication failed for'https'
    获取jwt(json web token)中存储的用户信息
    System.data.sqlclient.sqlexception:将截断字符串或二进制数据终止
    代码热更新
    左手坐标系 vs 右手坐标系
    GPU相关临时笔记
  • 原文地址:https://www.cnblogs.com/ljy0905/p/4727413.html
Copyright © 2011-2022 走看看