empty excel export file

2 posts, 1 answers
  1. Mario
    Mario avatar
    75 posts
    Member since:
    Jun 2009

    Posted 22 Jul 2009 Link to this post

    Hi,

    i get an empty excel file on ExcelExport.
    I already searched forum and found this thread:

    radgrid-export-to-excel-empty-spreadsheet.aspx

    I tried setting the MasterPage propertie UseAllDataFields="true", but i get an error at filling the radGrid with data. Like "The column name cant be set with <newnew>, because it wants a Int32 type.".

    I also got AutoGenerateColumns="false", i guess its pretty much working like the propertie UseAllDataFields and so it dont fit my custom columns.

    Q: What can i change when i not autogenerating?

    aspx:

    <telerik:RadGrid ID="radGrid" runat="server"  
                                                AllowPaging="True"  
                                                PageSize="30" 
                                                AllowSorting="True"  
                                                AutoGenerateColumns="False" 
                                                GridLines="Both" 
                                                OnExcelMLExportStylesCreated="RadGrid_ExcelMLExportStylesCreated" 
                                                OnExcelMLExportRowCreated="RadGrid_ExcelMLExportRowCreated" 
                                                OnItemCommand="Radgrid_GridCommand" 
                                                OnNeedDataSource="Radgrid_NeedDatasource"
                                                 
                                    <MasterTableView DataKeyNames="id"  
                                        CommandItemDisplay="Bottom"
                                     
                                        <CommandItemTemplate> 
                                         
                                            <div style="padding: 5px 5px; align: right;"
                                                <asp:ImageButton ID="btnExportToExcel" runat="server"  
                                                            ImageUrl="~/App_Themes/Default/Images/excelfile_icon.gif"  
                                                            OnClick="btnExportToExcel_Click" /> 
                                                <asp:Label ID="lblRelationAdd" runat="server"  
                                                            Text="exportToExcel"  
                                                            OnLoad="OnLabelLoad"></asp:Label> 
                                            </div> 
                                        </CommandItemTemplate> 
                                                                                         
                                        <Columns> 
     
                                            <telerik:GridBoundColumn DataField="id" Visible="false"></telerik:GridBoundColumn> 
                                            <telerik:GridButtonColumn ButtonType="ImageButton" ImageUrl="../App_Themes/Default/Images/file_icon.gif" CommandArgument="id"  CommandName="OpenFile"></telerik:GridButtonColumn> 
                                            <telerik:GridTemplateColumn> 
                                                <ItemTemplate> 
                                                    <asp:Image runat="server" ID="imgNew" 
                                                        OnLoad="OnImageLoad" /> 
                                                    <asp:TextBox ID="txbNewCreatedDate" runat="server" 
                                                        Visible ="false" 
                                                        Text='<%# DataBinder.Eval(Container.DataItem,"created_date").ToString() %>' /> 
                                                </ItemTemplate> 
                                            </telerik:GridTemplateColumn> 
                                            <telerik:GridHyperLinkColumn DataTextField="Metainformation.name" HeaderText="Profile" DataNavigateUrlFormatString="DocumentProfile.aspx?id={0}" DataNavigateUrlFields="id" ></telerik:GridHyperLinkColumn> 
                                            <telerik:GridBoundColumn DataField="Category.name" HeaderText="Kategorie"></telerik:GridBoundColumn> 
                                            <telerik:GridBoundColumn DataField="User.lastname" HeaderText="Ersteller"></telerik:GridBoundColumn> 
                                            <telerik:GridBoundColumn DataField="created_date" HeaderText="Erstellungsdatum"></telerik:GridBoundColumn> 
                                            <telerik:GridBoundColumn DataField="User1.lastname" HeaderText="letzter Bearbeiter"></telerik:GridBoundColumn> 
                                            <telerik:GridTemplateColumn HeaderText="inuse"
                                                <ItemTemplate> 
                                                    <asp:Image runat="server" ID="imgInUse" 
                                                        OnLoad="OnImageLoad"/> 
                                                    <asp:TextBox ID="txbInEditMode" runat="server" 
                                                        Visible ="false" 
                                                        Text='<%# DataBinder.Eval(Container.DataItem,"is_ineditmode").ToString() %>' /> 
                                                    <asp:TextBox ID="txbIsCheckedout" runat="server" 
                                                        Visible ="false" 
                                                        Text='<%# DataBinder.Eval(Container.DataItem,"is_checkedout").ToString() %>' /> 
                                                </ItemTemplate> 
                                            </telerik:GridTemplateColumn> 
                                            <telerik:GridBoundColumn DataField="checkout_date" DataType="System.DateTime" HeaderText="in Verwendung seit"></telerik:GridBoundColumn> 
                                            <telerik:GridBoundColumn DataField="Folder.name" HeaderText="Ordner"></telerik:GridBoundColumn> 
                                            <telerik:GridTemplateColumn HeaderText="inuse"
                                                <ItemTemplate> 
                                                    <asp:ImageButton runat="server" ID="btnDelete" 
                                                        OnLoad="OnImageButtonLoad" OnClick="btnDelete_OnClick"/> 
                                                    <asp:TextBox ID="txbDeleteInEditMode" runat="server" 
                                                        Visible ="false" 
                                                        Text='<%# DataBinder.Eval(Container.DataItem,"is_ineditmode").ToString() %>' /> 
                                                    <asp:TextBox ID="txbDeleteIsCheckedout" runat="server" 
                                                        Visible ="false" 
                                                        Text='<%# DataBinder.Eval(Container.DataItem,"is_checkedout").ToString() %>' /> 
                                                    <asp:TextBox ID="txbDeleteId" runat="server" 
                                                        Visible ="false" 
                                                        Text='<%# DataBinder.Eval(Container.DataItem,"id").ToString() %>' /> 
                                                </ItemTemplate> 
                                            </telerik:GridTemplateColumn> 
                                             
                                        </Columns> 
                                           
                                        <RowIndicatorColumn> 
                                            <HeaderStyle Width="20px"></HeaderStyle> 
                                        </RowIndicatorColumn> 
     
                                        <ExpandCollapseColumn> 
                                            <HeaderStyle Width="20px"></HeaderStyle> 
                                        </ExpandCollapseColumn> 
                                    </MasterTableView> 
                                    <ClientSettings AllowColumnsReorder="True" ReorderColumnsOnClient="True"
                                        <ClientEvents OnRowContextMenu="RowContextMenu"></ClientEvents> 
                                        <Selecting AllowRowSelect="true" /> 
                                    </ClientSettings> 
                                </telerik:RadGrid> 

    code behind:

    protected void btnExportToExcel_Click(object sender, EventArgs e) 
            { 
                // configure 
                radGrid.ExportSettings.IgnorePaging = true
                radGrid.ExportSettings.Excel.Format = GridExcelExportFormat.ExcelML; 
                radGrid.ExportSettings.ExportOnlyData = true
     
                // export 
                radGrid.MasterTableView.ExportToExcel(); 
            } 
     
            protected void RadGrid_ExcelMLExportRowCreated(object source, Telerik.Web.UI.GridExcelBuilder.GridExportExcelMLRowCreatedArgs e) 
            { 
      
            } 
     
            protected void RadGrid_ExcelMLExportStylesCreated(object source, Telerik.Web.UI.GridExcelBuilder.GridExportExcelMLStyleCreatedArgs e) 
            { 
                foreach (Telerik.Web.UI.GridExcelBuilder.StyleElement style in e.Styles) 
                { 
                    if (style.Id == "headerStyle"
                    { 
                        style.FontStyle.Bold = true
                        style.FontStyle.Color = System.Drawing.Color.Gainsboro; 
                        style.InteriorStyle.Color = System.Drawing.Color.Wheat; 
                        style.InteriorStyle.Pattern = Telerik.Web.UI.GridExcelBuilder.InteriorPatternType.Solid; 
                    } 
                    else if (style.Id == "itemStyle"
                    { 
                        style.InteriorStyle.Color = System.Drawing.Color.WhiteSmoke; 
                        style.InteriorStyle.Pattern = Telerik.Web.UI.GridExcelBuilder.InteriorPatternType.Solid; 
                    } 
                    else if (style.Id == "alternatingItemStyle"
                    { 
                        style.InteriorStyle.Color = System.Drawing.Color.LightGray; 
                        style.InteriorStyle.Pattern = Telerik.Web.UI.GridExcelBuilder.InteriorPatternType.Solid; 
                    } 
                } 
     
                Telerik.Web.UI.GridExcelBuilder.StyleElement myStyle = new Telerik.Web.UI.GridExcelBuilder.StyleElement("MyCustomStyle"); 
                myStyle.FontStyle.Bold = true
                myStyle.FontStyle.Italic = true
                myStyle.InteriorStyle.Color = System.Drawing.Color.Gray; 
                myStyle.InteriorStyle.Pattern = Telerik.Web.UI.GridExcelBuilder.InteriorPatternType.Solid; 
                e.Styles.Add(myStyle); 
            } 


    Or shall i fill another invisible radGrid with AutoGenerateColumns="true" and call thats ExportToExcel()

    cheers mario

  2. Answer
    Daniel
    Admin
    Daniel avatar
    4945 posts

    Posted 23 Jul 2009 Link to this post

    Hello Mario,

    I'm afraid that ExcelML export engine doesn't support nested properties. You should create a custom entity that flattens your data object structure.

    Regards,
    Daniel
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top