首页 > 其他 > 详细

devexpress 多控件导出到excel

时间:2019-12-05 11:25:24      阅读:122      评论:0      收藏:0      [点我收藏+]
  /// <summary>
        /// 导出多个控件数据到excel中
        /// </summary>
        /// <param name="FileName">文件名</param>
        /// <param name="tables">控件列表</param>
        /// <returns></returns>
        public static string ControlExportToXlsxNoOpen(string FileName, params IPrintable[] tables)
        {
            string path = "";
            try
            {

                SaveFileDialog sfd = new SaveFileDialog();
                sfd.Filter = "Excel文件|*.xlsx;";
                sfd.FileName = FileName;
                sfd.Title = "导出" + FileName;
                if (sfd.ShowDialog() == DialogResult.OK)
                {
                    DevExpress.XtraPrinting.XlsxExportOptions options = new DevExpress.XtraPrinting.XlsxExportOptions();
                    options.SheetName = FileName;
                    options.ExportMode = XlsxExportMode.SingleFilePageByPage;
                    path = sfd.FileName;

                    var defautps = new DevExpress.XtraPrinting.PrintingSystem();
                    PrintableComponentLink pclink = null;
                    CompositeLink compLink = new CompositeLink(defautps);
                    foreach (var tbl in tables)
                    {
                        pclink = new PrintableComponentLink();
                        pclink.Component = tbl;
                        compLink.Links.Add(pclink);
                    }

                    #region 分Sheet
                    // 用于每个Link生成一个Sheet,不使用此方法,则合并在一个Sheet内
                    compLink.CreatePageForEachLink();
                    compLink.ExportToXlsx(path, options);
                    #endregion 分Sheet
                }
            }
            catch (Exception ex)
            {
                LogUtils.Error(ex.Message);
                Error(ex.Message);
            }
            return path;
        }

 

devexpress 多控件导出到excel

原文:https://www.cnblogs.com/coder-soldier/p/11987730.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!