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

ExportToXlsx only exports the last item of the grid.

4 Answers 61 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Odd Veibust
Top achievements
Rank 1
Odd Veibust asked on 29 Sep 2015, 06:26 AM

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
             });
    }
}

4 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 29 Sep 2015, 07:10 AM
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
0
Odd Veibust
Top achievements
Rank 1
answered on 29 Sep 2015, 07:26 AM

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>

0
Maya
Telerik team
answered on 29 Sep 2015, 08:12 AM
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
0
Odd Veibust
Top achievements
Rank 1
answered on 29 Sep 2015, 09:12 AM
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.
Tags
GridView
Asked by
Odd Veibust
Top achievements
Rank 1
Answers by
Maya
Telerik team
Odd Veibust
Top achievements
Rank 1
Share this question
or