ExportToXlsx only exports the last item of the grid.

5 posts, 0 answers
  1. Odd Veibust
    Odd Veibust avatar
    26 posts
    Member since:
    Feb 2007

    Posted 29 Sep 2015 Link to this post

    Hi.

    I tried to use ExportToXlsx to export a grid to Excel. I used your example (below), but it will only export the last item of the grid. Do you have any idea what can be wrong? I have sold it by using Spreadsheet and building the xlsx by looping through each item, but it would be nicer and easier to use ExportToXlsx.

    - Odd

               

    string extension = "xlsx";
     
    SaveFileDialog dialog = new SaveFileDialog()
    {
        DefaultExt = extension,
        FileName = "GiekExport.xlsx",
        Filter = String.Format("{1} files (*.{0})|*.{0}|All files (*.*)|*.*", extension, "Excel"),
        FilterIndex = 1
    };
     
    if (dialog.ShowDialog() == true)
    {
        using (Stream stream = dialog.OpenFile())
        {
            GiekExcelGrid.ExportToXlsx(stream,
                 new GridViewDocumentExportOptions()
                 {
                     ShowColumnFooters = false,
                     ShowColumnHeaders = true,
                     ShowGroupFooters = false,
                     AutoFitColumnsWidth = true
                 });
        }
    }

  2. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 29 Sep 2015 Link to this post

    Hi Odd,

    That's a bit strange. Generally, ExportToXlsx will take into account all objects from the Items collection of the grid. Could you verify how many items there are before exporting (checking myGridView.Items.Count) ? Do you have paging/ filtering or anything more specific that you do ?  

    Regards,
    Maya
    Telerik
    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 Feedback Portal and vote to affect the priority of the items
  3. UI for WPF is Visual Studio 2017 Ready
  4. Odd Veibust
    Odd Veibust avatar
    26 posts
    Member since:
    Feb 2007

    Posted 29 Sep 2015 in reply to Maya Link to this post

    I have tried with different datasets (depends on result from database), but usually 30+ items. I also checked the count before ExportToXlsx is called, and the items are all there.

    There's no paging/filtering or anything else. The grid looks like this.

     

    <telerik:RadGridView x:Name="GiekExcelGrid" ScrollMode="RealTime"
                             Margin="0"
                             RowIndicatorVisibility="Collapsed"
                             IsReadOnly="True"
                             AutoGenerateColumns="False"
                             CanUserFreezeColumns="False"
                             CanUserResizeColumns="True"
                             ShowGroupPanel="False"
                             CanUserSelect="False"
                             IsFilteringAllowed="False"
                             ItemsSource="{Binding Path=GiekExports}">
            <telerik:RadGridView.Columns>
                <telerik:GridViewDataColumn Header="CustomerNumber" DataMemberBinding="{Binding Path=CustomerNumber}" Width="Auto" />
                <telerik:GridViewDataColumn Header="BuyerReference" DataMemberBinding="{Binding Path=BuyerReference}" Width="Auto" />
                <telerik:GridViewDataColumn Header="BuyerName" DataMemberBinding="{Binding Path=Buyername}" Width="*" />
                <telerik:GridViewDataColumn Header="Country" DataMemberBinding="{Binding Path=Country}" Width="Auto" />
                <telerik:GridViewDataColumn Header="LastTransactionDate" DataMemberBinding="{Binding Path=LastTransactionDate, StringFormat={}{0:dd.MM.yyyy}}" Width="Auto" />
                <telerik:GridViewDataColumn Header="SoldAmountNOK" DataMemberBinding="{Binding Path=SoldAmount, StringFormat={}{0:N2}}" Width="Auto" TextAlignment="Right" />
                <telerik:GridViewDataColumn Header="OutstandingAmountNOK" DataMemberBinding="{Binding Path=OutstandingAmount, StringFormat={}{0:N2}}" Width="Auto" TextAlignment="Right" />
            </telerik:RadGridView.Columns>
        </telerik:RadGridView>

  5. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 29 Sep 2015 Link to this post

    Hello Odd,

    It seems to look correct based on the code provided. So, in order to skip guessing, could you try modifying the attached project so that it illustrates the behavior you described and send it back to me ? 


    Regards,
    Maya
    Telerik
    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 Feedback Portal and vote to affect the priority of the items
  6. Odd Veibust
    Odd Veibust avatar
    26 posts
    Member since:
    Feb 2007

    Posted 29 Sep 2015 in reply to Maya Link to this post

    I'll see if I'm able to modify it later, busy at work now, and it's from a large project so it's kinda hard to extract everything needed.
Back to Top
UI for WPF is Visual Studio 2017 Ready