DEV 控件导出

关于DEV 控件pagedGridControl和gridControl导出Excel文件及。

一、导出

        公用部分

public class XtraGridExportHelper
        {
            private static SaveFileDialog _dlg = new SaveFileDialog();

            public static string ShowSaveFileDialog(string title, string filter, string fileName)
            {
                _dlg.Title = "导出到" + title;
                _dlg.FileName = fileName;
                _dlg.Filter = filter;
                if (_dlg.ShowDialog() == DialogResult.OK)
                    return _dlg.FileName;
                return "";
            }

            public static void OpenFile(string fileName)
            {
                if (XtraMessageBox.Show("导出完毕,要打开文件吗?", "导出", MessageBoxButtons.YesNo,
                MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    try
                    {
                        System.Diagnostics.Process process = new System.Diagnostics.Process();
                        process.StartInfo.FileName = fileName;
                        process.StartInfo.Verb = "Open";
                        process.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal;
                        process.Start();
                    }
                    catch (Exception ex)
                    {
                        XtraMessageBox.Show("打开文件失败。" + ex.Message,
                        Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
        }

        pagedGridControl 导出

string fileName = XtraGridExportHelper.ShowSaveFileDialog("Microsoft Excel", "Microsoft Excel|*.xls", this.Text);
            if (fileName != String.Empty)
            {
                pagedGridControl1.GridView.OptionsPrint.AutoWidth = false;
                pagedGridControl1.GridView.ExportToXls(fileName);
                XtraGridExportHelper.OpenFile(fileName);
            }

        gridControl导出


string fileName = XtraGridExportHelper.ShowSaveFileDialog("Microsoft Excel", "Microsoft Excel|*.xls", this.Text);
            if (fileName != String.Empty)
            {
                gridControl.OptionsPrint.AutoWidth = false;
                gridControl.ExportToXls(fileName);
                XtraGridExportHelper.OpenFile(fileName);
            }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值