This is a migrated thread and some comments may be shown as answers.

ExportToExcel using ExcelML exports only sort column

2 Answers 66 Views
Grid
This is a migrated thread and some comments may be shown as answers.
David Louth
Top achievements
Rank 1
David Louth asked on 02 Jul 2010, 05:25 PM
I have a grid with detail tables. I'm trying to Export to Excel. Using Just ExportToExcel works although I get a blank first column But I need to add styling and remove <br> from header text so I thought I'd use ExcelML format. This produces only the data for whichever is the current sort column and notthing else.
 
<telerik:RadGrid ID="rgInvoices" runat="server" GridLines="None" AllowPaging="True" 
    AllowMultiRowSelection="true" ShowStatusBar="true" AllowSorting="True" AutoGenerateColumns="False" 
    GroupingEnabled="False" Skin="CentreTelerikNoSelectStyle" EnableEmbeddedSkins="false" 
    OnNeedDataSource="rgInvoices_NeedDataSource" PageSize="10" OnItemCreated="rgInvoices_ItemCreated" 
    OnItemDataBound="rgInvoices_ItemDataBound" OnDetailTableDataBind="rgInvoices_DetailTableDataBind" 
    HeaderStyle-Font-Bold="true" OnExcelMLExportStylesCreated="RadGrid1_ExcelMLExportStylesCreated" 
    OnExcelMLExportRowCreated="RadGrid1_ExcelMLExportRowCreated">  
   <ClientSettings> 
        <Selecting AllowRowSelect="True" EnableDragToSelectRows="false" /> 
        <ClientEvents OnRowSelecting="CancelNonInputSelect" OnRowDeselecting="CancelNonInputSelect" /> 
    </ClientSettings> 
    <MasterTableView OverrideDataSourceControlSorting="True" DataKeyNames="PK,InvoiceType,Number,DealerRefNumber,DueDate,OriginalAmount,OpenAmount,TransactionType" 
        AllowNaturalSort="false" CommandItemDisplay="Top" CommandItemStyle-Font-Bold="true">  
        <CommandItemTemplate> 
            <div style="padding: 5px 20px 5px 5px; text-align: left; float: left">  
                <asp:Label ID="lblSearchResults" class="ReportTitleBold" SkinID="none" runat="server" 
                    meta:resourcekey="lblInvoices"></asp:Label>&nbsp;&nbsp;  
                <CENTRE:CentreImageButton ID="btnAddToSelectedInvoices" runat="server" meta:resourcekey="btnAddToSelectedInvoices" 
                    CausesValidation="false" OnClick="btnAddToSelectedInvoices_Click"></CENTRE:CentreImageButton>&nbsp;  
                <CENTRE:CentreImageButton ID="btnExportAll" runat="server" meta:resourcekey="btnExportAll" OnClick="btnExportAll_Click"></CENTRE:CentreImageButton> 
            </div> 
            <div style="padding: 5px 5px 5px 0px; float: right; white-space: nowrap">  
                <asp:Label ID="lblTotals" runat="server" meta:resourcekey="lblTotals"></asp:Label>&nbsp;  
                <asp:Label ID="lblTotalOpenAmount" runat="server"></asp:Label>&nbsp;</div> 
            <div style="clear: both;"></div> 
        </CommandItemTemplate> 
        <SortExpressions> 
            <telerik:GridSortExpression FieldName="DueDate" SortOrder="Ascending" /> 
        </SortExpressions> 
        <Columns> 
            <telerik:GridTemplateColumn HeaderText="<%$ Resources:PaymentHistoryHeader %>" HeaderStyle-HorizontalAlign="Center" 
                ItemStyle-HorizontalAlign="Center" UniqueName="PaymentLog">  
                <ItemTemplate> 
                    <asp:ImageButton ID="btnLog" runat="server" ImageUrl="~/images/magnify.gif" CommandName="PaymentLog" CommandArgument='<%# Eval("Number") %>' /> 
                </ItemTemplate> 
            </telerik:GridTemplateColumn> 
            <telerik:GridClientSelectColumn UniqueName="SelectColumn" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" /> 
            <telerik:GridBoundColumn HeaderText="<%$ Resources:NumberHeader %>" DataField="Number"></telerik:GridBoundColumn> 
            <telerik:GridNumericColumn HeaderText="<%$ Resources:DealerRefNumberHeader %>" DataField="DealerRefNumber"></telerik:GridNumericColumn> 
            <telerik:GridBoundColumn HeaderText="<%$ Resources:StatusHeader %>" DataField="Status"></telerik:GridBoundColumn> 
            <telerik:GridBoundColumn HeaderText="<%$ Resources:NameHeader %>" DataField="Name"></telerik:GridBoundColumn> 
            <telerik:GridBoundColumn HeaderText="<%$ Resources:TransactionDateHeader %>" DataField="TransactionDate" 
                DataFormatString="{0:d}" DataType="System.DateTime"></telerik:GridBoundColumn> 
            <telerik:GridBoundColumn HeaderText="<%$ Resources:PostedDateHeader %>" DataField="PostedDate" 
                DataFormatString="{0:d}" DataType="System.DateTime"></telerik:GridBoundColumn> 
            <telerik:GridBoundColumn HeaderText="<%$ Resources:DueDateHeader %>" DataField="DueDate" 
                DataFormatString="{0:d}" DataType="System.DateTime"></telerik:GridBoundColumn> 
            <telerik:GridBoundColumn HeaderText="<%$ Resources:OriginalAmountHeader %>" DataField="OriginalAmount" 
                DataFormatString="{0:N}" ItemStyle-HorizontalAlign="Right" HeaderStyle-HorizontalAlign="Right">  
            </telerik:GridBoundColumn> 
            <telerik:GridBoundColumn HeaderText="<%$ Resources:OpenAmountHeader %>" DataField="OpenAmount" 
                DataFormatString="{0:N}" ItemStyle-HorizontalAlign="Right" HeaderStyle-HorizontalAlign="Right">  
            </telerik:GridBoundColumn> 
        </Columns> 
        <DetailTables> 
            <telerik:GridTableView Width="100%">  
                <Columns> 
                    <telerik:GridBoundColumn DataField="Field2"></telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn DataField="Field3"></telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn DataField="Field4"></telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn DataField="Field5"></telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn DataField="Field6"></telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn DataField="Field7"></telerik:GridBoundColumn> 
                </Columns> 
            </telerik:GridTableView> 
        </DetailTables> 
    </MasterTableView> 
    <PagerStyle Mode="NextPrevAndNumeric" PagerTextFormat="<%$ Resources:CommonStrings,RadGridPagerTextFormat %>" /> 
</telerik:RadGrid> 
 
protected void btnExportAll_Click(object sender, ImageClickEventArgs e)  
{  
    rgInvoices.ExportSettings.ExportOnlyData = true;  
    rgInvoices.ExportSettings.IgnorePaging = true;  
    rgInvoices.ExportSettings.OpenInNewWindow = true;  
    rgInvoices.ExportSettings.FileName = "InvoiceActivity";  
    rgInvoices.ExportSettings.Excel.Format = Telerik.Web.UI.GridExcelExportFormat.ExcelML;  
    rgInvoices.Columns.FindByUniqueName("PaymentLog").Display = false;  
    rgInvoices.Columns.FindByUniqueName("SelectColumn").Display = false;  
    rgInvoices.MasterTableView.HierarchyDefaultExpanded = true;  
    rgInvoices.Rebind();  
    //foreach (GridItem commandItem in rgInvoices.MasterTableView.GetItems(GridItemType.CommandItem))  
    //{  
    //    commandItem.Visible = false;  
    //}  
 
    rgInvoices.MasterTableView.ExportToExcel();  

The _ExcelML methods are empty so it's not happening because of them.
The initial sort is by Due Date. If I change the sort column, I get that column in the export but nothing else.

This is all I get:
Due Date
11/15/2009 0:00
11/15/2009 0:00
...

Thanks,
Dave

2 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 08 Jul 2010, 08:12 AM
Hello David,

I'm unable to reproduce the problem on my end so I created a runnable demo, based on your project. Please download this sample and let me know how to modify it in order to recreate your scenario.

Best regards,
Daniel
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
David Louth
Top achievements
Rank 1
answered on 08 Jul 2010, 03:59 PM
Thanks, I'll let you know. It may be two weeks until I get to it as I'm on vacation after today.
Tags
Grid
Asked by
David Louth
Top achievements
Rank 1
Answers by
Daniel
Telerik team
David Louth
Top achievements
Rank 1
Share this question
or