RadGrid 导出到 Excel

发布于 2024-07-26 00:44:23 字数 1296 浏览 2 评论 0原文

我有一个 radgrid,可以根据用户输入动态生成列。 填充网格后,用户可以选择导出到 Excel 或 Word。 但是,当用户想要保留页面格式时,不会导出任何数据。 但如果用户随后选择忽略分页,则一切正常。

因此,如果 radgrid 属性“AutoGenerateColumns”设置为 false,并且“IgnorePaging”也设置为 false,则似乎不会导出数据。

其他人也有这个问题还是我忽略了什么?

以下是配置和调用导出的方法:

    private void ConfigureReport(string strExportType)
    {
        switch (strExportType.ToLower())
        {
            case "excel":
                RadGrid1.ExportSettings.FileName = "RadGridExportToExcel";
                break;

            case "word":
                RadGrid1.ExportSettings.FileName = "RadGridExportToWord";
                break;
        }
        RadGrid1.ExportSettings.IgnorePaging = this.cbxPaging.Checked;
        RadGrid1.ExportSettings.ExportOnlyData = this.cbxFormat.Checked;
    }

    private void btnExcel_Click(object sender, EventArgs e)
    {
        if (this.UserProcess.SearchResults != null &&    
            this.UserProcess.SearchResults.Count > 0)
        { 
            ConfigureReport("excel");
            RadGrid1.MasterTableView.ExportToExcel();
        }
        else
        {
            this.lblError.Text = AAILocalization.GetLocaleText("Error:NoResultExport");
        }
    }

提前感谢您的帮助:) 帕特

​ 为了勇敢起见,我排除了创建列的方法。

I have a radgrid that generates columns dynamically based on user input. Once the grid is populated, the user has the option to export to excel or word. However when the user want's to retain the page formatting, no data is getting exported. But if the user then selects to ignore paging, everything works fine.

So it seems that if the radgrid property "AutoGenerateColumns" is set to false, and "IgnorePaging" is also false, data isn't getting exported.

Anyone else have this problem or am I over looking something?

Here are the methods that configure and call the export:

    private void ConfigureReport(string strExportType)
    {
        switch (strExportType.ToLower())
        {
            case "excel":
                RadGrid1.ExportSettings.FileName = "RadGridExportToExcel";
                break;

            case "word":
                RadGrid1.ExportSettings.FileName = "RadGridExportToWord";
                break;
        }
        RadGrid1.ExportSettings.IgnorePaging = this.cbxPaging.Checked;
        RadGrid1.ExportSettings.ExportOnlyData = this.cbxFormat.Checked;
    }

    private void btnExcel_Click(object sender, EventArgs e)
    {
        if (this.UserProcess.SearchResults != null &&    
            this.UserProcess.SearchResults.Count > 0)
        { 
            ConfigureReport("excel");
            RadGrid1.MasterTableView.ExportToExcel();
        }
        else
        {
            this.lblError.Text = AAILocalization.GetLocaleText("Error:NoResultExport");
        }
    }

Thanks in advance for the help:)
Pat

P.S. i've excluded the method that creates the columns for bravity's sake.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

南笙 2024-08-02 00:44:23

这里没有足够的信息来提供确切的原因/解决方案,但是一个建议(实际上更多的是一种解决方法)是在用户导出时始终设置IgnorePaging。 这是一些示例代码:

private void btnExcel_Click(object sender, EventArgs e)
    {
        if (this.UserProcess.SearchResults != null &&    
            this.UserProcess.SearchResults.Count > 0)
        { 
            ConfigureReport("excel");
            RadGrid1.MasterTableView.AllowPaging = false;
            RadGrid1.PageSize = RadGrid1.Items.Count + 1;
            RadGrid1.MasterTableView.ExportToExcel();
        }
        else
        {
            this.lblError.Text = AAILocalization.GetLocaleText("Error:NoResultExport");
        }
    }

There isn't enough information here to provide an exact cause/solution, however one suggestion (really more of a workaround) is to always set IgnorePaging when the user is exporting. Here is some sample code:

private void btnExcel_Click(object sender, EventArgs e)
    {
        if (this.UserProcess.SearchResults != null &&    
            this.UserProcess.SearchResults.Count > 0)
        { 
            ConfigureReport("excel");
            RadGrid1.MasterTableView.AllowPaging = false;
            RadGrid1.PageSize = RadGrid1.Items.Count + 1;
            RadGrid1.MasterTableView.ExportToExcel();
        }
        else
        {
            this.lblError.Text = AAILocalization.GetLocaleText("Error:NoResultExport");
        }
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文