radgrid控件缺少的字段导出到Excel时 [英] Radgrid missing fields when exporting to Excel

查看:565
本文介绍了radgrid控件缺少的字段导出到Excel时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

my.ascx >>

my.ascx >>

<telerik:RadAjaxPanel ID="ajaxPanel_Header" runat="server">
  <asp:Button ID="Button_ExportToExcel" runat="server" Text="" CssClass="ExportToExcel" UseSubmitBehavior="False" OnClick="Button_ExportToExcel_Click" />
   <telerik:RadGrid ID="grid_Permission" runat="server" AutoGenerateColumns="False" PageSize="200" GridLines="None" CellSpacing="0" AllowSorting="True" ShowGroupPanel="True" ShowFooter="True" OnNeedDataSource="grid_Permission_NeedDataSource" OnItemDataBound="grid_Permission_ItemDataBound" OnDetailTableDataBind="grid_Permission_DetailTableDataBind" OnItemCommand="grid_Permission_ItemCommand">
      ...
      ...
      ...
      <MasterTableView CellSpacing="-1" NoMasterRecordsText="Kayıt bulunamadı." DataKeyNames="MrkDocHeaderId,ProdStoreOrderDetailId,IsStoreOutSubscribed,ProdStoreStockTypeId" HierarchyLoadMode="ServerOnDemand" Name="tbl_Master" EnableHeaderContextMenu="True" GroupLoadMode="Client" AllowPaging="True" PageSize="10">     
         ...
         ...                                               
         <telerik:GridBoundColumn HeaderText="Onay Durumu" DataField="IsStoreOutSubscribedText" FilterControlAltText="Filter IsStoreOutSubscribedText column" UniqueName="IsStoreOutSubscribedText" Visible="False" Exportable="true">
            <ColumnValidationSettings>
               <ModelErrorMessage Text="" />
            </ColumnValidationSettings>
         </telerik:GridBoundColumn>
      </MasterTableView>
   </telerik:RadGrid>
</telerik:RadAjaxPanel>

my.ascx.cs >>

my.ascx.cs >>

protected void Button_ExportToExcel_Click(object sender, EventArgs e)
{
    //RadGrid grid = grid_Permission;
    if (grid_Permission != null)
    {
        if (grid_Permission.Items.Count > 0)
        {
            try
            {
                //grid_Permission.ExportSettings.Excel.Format = GridExcelExportFormat.Biff;
                grid_Permission.ExportSettings.FileName = string.Format("MamulDepoUrunRaporu_{0}", DateTime.Now);
                grid_Permission.ExportSettings.IgnorePaging = true;
                grid_Permission.ExportSettings.OpenInNewWindow = true;
                grid_Permission.ExportSettings.ExportOnlyData = true;
                grid_Permission.MasterTableView.UseAllDataFields = true;
                //grid_Permission.MasterTableView.GetColumn("img_IsStoreOutSubscribed").Visible = false;
                grid_Permission.MasterTableView.ExportToExcel();

            }
            finally
            {
            }
        }
    }
}

下面是我的问题:

我有一个Telerik的radgrid控件。我想导出到Excel此网格,可见或不可见的一些领域。
但在我导出的文件,我不能看到即使它们被标记在的visible = false 字段值可导出=真正的

I have a telerik radgrid. I want to export to excel some fields of this grid, visible or not. But in my exported file i cannot see the visible=false field values even they are marked Exportable="true"

我试着列的可见性更改为true出口前,重新设置假等没有什么改变。

I tried to change column visibilty to true before the export and set false again etc. nothing is changed.

这是什么缘故任何想法?

Any ideas about the reason?

推荐答案

我不知道你的问题的根源,然而,这就是我要做的导出到Excel表和它的作品。

I am not sure about the origin of your problem, however this is how I do export to excel and it works.

 protected void ExpExcel_Click(object sender, EventArgs e)
    {
        //exclude columns from being exported in excel
        foreach (GridColumn col in RadGrid1.MasterTableView.Columns)
        {
            if ((col.UniqueName.Contains("EditCommandColumn")) ||
                (col.UniqueName.Contains("column1")))
            {
                col.Display = false;
            }
            else
            {
                col.Display = true;
            }
        }
        //format content to be exported in excel
        foreach (GridFilteringItem item in RadGrid1.MasterTableView.GetItems(GridItemType.FilteringItem))

        item.Visible = false;
       //the other settings you need...
        RadGrid1.ExportSettings.FileName = "yourFileName;
        RadGrid1.ExportSettings.ExportOnlyData = true;
        RadGrid1.ExportSettings.Excel.Format = Telerik.Web.UI.GridExcelExportFormat.ExcelML;
       //example of renaming column header in excel            
        RadGrid1.MasterTableView.Columns.FindByUniqueName("something").HeaderText = "something else";
        //finally export the columns
        RadGrid1.MasterTableView.ExportToExcel();
    }

让我们知道这是不是帮助。

Let us know if this is of help.

这篇关于radgrid控件缺少的字段导出到Excel时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆