zoukankan      html  css  js  c++  java
  • DEV控件之GridControl导出到Excel

    DEV控件之GridControl导出到Excel  

    2013-05-29 08:52:53|  分类: C# WinForm|举报|字号 订阅

     
     

    1、

    SaveFileDialog fileDialog = new SaveFileDialog();
    fileDialog.Title = "导出Excel";
    fileDialog.Filter = "Excel文件(*.xls)|*.xls";
    DialogResult dialogResult = fileDialog.ShowDialog(this);
    if (dialogResult == DialogResult.OK)
    {
    DevExpress.XtraPrinting.XlsExportOptions options = new DevExpress.XtraPrinting.XlsExportOptions();
    gridControl1.ExportToXls(fileDialog.FileName);
    DevExpress.XtraEditors.XtraMessageBox.Show("保存成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
    }

     

    2、 public override void ImportExcel()
            {
                if (XtraMessageBox.Show("确定要将本页面数据导入到Excel内?") == DialogResult.OK)
                {
                    try
                    {
                        if (this.DataSourceTable == null || this.DataSourceTable.Rows.Count == 0)
                        {
                            XtraMessageBox.Show("没有数据要导出!");
                            return;
                        }
                        this.SaveFileDialog.Filter = "Excel文件(*.xls)|*.xls";
                        if (this.SaveFileDialog.ShowDialog(this) == DialogResult.OK)
                        {
                            BaseFormFactory.ProcessFactory.Show(this, "数据导出开始");
                            ExportTo(new DevExpress.XtraExport.ExportXlsProvider(this.SaveFileDialog.FileName));
                        }

                                      }
                    catch (Exception vErr)
                    {
                        XtraMessageBox.Show("导出数据失败!错误源:" + vErr.Message);
                    }
                    finally
                    {
                        BaseFormFactory.ProcessFactory.Close();
                        XtraMessageBox.Show("导出成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
            }
            private void ExportTo(DevExpress.XtraExport.IExportProvider provider)
            {
                DevExpress.XtraGrid.Export.BaseExportLink link = this.gridData.gridView2.CreateExportLink(provider);
                (link as DevExpress.XtraGrid.Export.GridViewExportLink).ExpandAll = false;
                link.ExportTo(true);
                provider.Dispose();
            }

  • 相关阅读:
    刷题86—动态规划(三)
    刷题85—动态规划(二)— 股票6道
    刷题84—动态规划(一)
    刷题83——硬币
    刷题82——二叉树的右视图
    刷题81——统计「优美子数组」
    android adb 流程原理代码分析(一)
    android默认开启adb调试方法分析
    recovery 下界面UI旋转90 180 270修改
    sublime使用Package Control不能正常使用的解决办法
  • 原文地址:https://www.cnblogs.com/gaohao/p/3591310.html
Copyright © 2011-2022 走看看