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

export to Excel - including IValueConverter and all the pages of GridView

17 Answers 166 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
lina fetisova
Top achievements
Rank 1
lina fetisova asked on 02 Aug 2010, 07:32 AM
Good day!
We make export to Exxel from our GridViews using ExportExtensions.ToCsv(grid, true);

we use it in our function:

public static void ExportToXls(RadGridView grid)
        {
            SaveFileDialog textDialog = new SaveFileDialog();
            textDialog.Filter = "XLS Files | *.csv";
            textDialog.DefaultExt = "csv";
            bool? result = textDialog.ShowDialog();
            if (result == true)
            {
                  System.Text.Encoding ascii = System.Text.Encoding.UTF8;
                  Encoding enc=Encoding.GetEncoding("cp1251");
                  string data = ExportExtensions.ToCsv(grid, true);
                  data = data.Replace(",", ";");
                  System.IO.Stream fileStream = textDialog.OpenFile();
                  byte[] contents = enc.GetBytes(data);
                  fileStream.Write(contents, 0, contents.Length);
                  fileStream.Flush();
                  fileStream.Close();
            }
        }    
     

But when we use different IValueConverters in our grid to convert the data in cells to user friendly data, in csv we see not user friendy data, without impact of IValueConverters.
That's the first problem.
Enother problem is when we use paging in our grid, there is only the current page in our csv file - but there are no other pages!
=(
how can I solve this problems?

17 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 02 Aug 2010, 08:03 AM
Hi ,

 I'm not sure about these IValueConverter problems however you can send us an example project where we can reproduce this issue. You may need to check our demo to know more how to export paged data. 

Best wishes,
Vlad
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
lina fetisova
Top achievements
Rank 1
answered on 02 Aug 2010, 09:28 AM
Vlad, thank you very much - but that's a pity - we use older version of Telerik and Silverlight 3. Do you have any ideas for Silverlight 3 and previous version of Telerik?
0
Vlad
Telerik team
answered on 02 Aug 2010, 09:59 AM
Hi,

 Indeed the example is for Silverlight 4 however you can use the same approach with Silverlight 3 as well. 

Best wishes,
Vlad
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
lina fetisova
Top achievements
Rank 1
answered on 02 Aug 2010, 10:08 AM
oh, that's great if it really works, Vlad, but I have a strange bug:
I try to export like in the example - http://demos.telerik.com/silverlight/#GridView/ExportingPagedData

i write such usings:

using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Navigation;
using System.Text;
using System.IO;
using System.IO.IsolatedStorage;
using System.Globalization;
using System.Windows.Controls.Primitives;
using System.Windows.Data;
using Telerik.Windows.Controls.GridView;
using Telerik.Windows.Data;
using Telerik.Windows.Controls;
using System.ServiceModel;


it includes all the includes from the example.
but I have a bug:
on line
GridViewExportOptions exportOptions = new GridViewExportOptions();
such a bug:
The type or namespace name 'GridViewExportOptions' could not be found (are you missing a using directive or an assembly reference?) 
and on line:
grStatistics.Export(stream, exportOptions); (grStatistics is a RadGridView)
suuch a bug:
'Telerik.Windows.Controls.RadGridView' does not contain a definition for 'Export' and no extension method 'Export' accepting a first argument of type 'Telerik.Windows.Controls.RadGridView' could be found (are you missing a using directive or an assembly reference?) 

what I do wrong?
0
Vlad
Telerik team
answered on 02 Aug 2010, 04:22 PM
Hi,

 Do you have our latest Silverlight 3 version?

All the best,
Vlad
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
lina fetisova
Top achievements
Rank 1
answered on 03 Aug 2010, 03:32 AM
Vlad, info about the installer:

This installer database contains the logic and data required to install Telerik RadControls for Silverlight Q3 2009 SP2.
0
Vlad
Telerik team
answered on 03 Aug 2010, 06:51 AM
Hello,

Indeed this is old version and GridViewExportOptions is available only in our latest versions. You can use old ToXXX methods in your case.

Regards,
Vlad
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
Mike
Top achievements
Rank 2
answered on 06 Dec 2011, 03:32 PM
Your demo seems to be broken. Silverlight loads but nothing is displayed. 

Mike
0
Vlad
Telerik team
answered on 06 Dec 2011, 03:35 PM
Hello Mike,

 This demo was removed. 

Kind regards,
Vlad
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Mike
Top achievements
Rank 2
answered on 06 Dec 2011, 04:20 PM
So is there a demo/code snippet that shows how to export all data for a paged collection data source?

Mike
0
Vlad
Telerik team
answered on 06 Dec 2011, 04:24 PM
Hi,

 If your grid is bound to a service you will need to download all the the data to the client which is not the efficient way. It will be better to export on the server-side using Telerik Reporting and download the document directly. 

Kind regards,
Vlad
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Mike
Top achievements
Rank 2
answered on 06 Dec 2011, 04:38 PM
Thanks for the quick responses. I suspect we're going to disagree on this. Sending the exported file across the wire to the client as opposed to just the data isn't going to save time, even though I do the export processing on the server. So unless there is a significant time saving, the simple approach is what we'll use. That said, I still would like to see how it is done, even if I have to load all of the data. Do I set the GridViewExportOptions.Items to the full data set?

Thanks,
Mike
0
Vlad
Telerik team
answered on 06 Dec 2011, 04:46 PM
Hello,

 Indeed you will need to download all the items on the client and use them for exporting. 

Regards,
Vlad
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Mike
Top achievements
Rank 2
answered on 06 Dec 2011, 05:05 PM
So I've gathered. However, that doesn't answer the question about how I force the export of all items. My inclination is to add an exporting event handler to the grid view and set export options there. It would be nice to see an example of doing this in association with a RIA service.

Thanks,
Mike
0
Vlad
Telerik team
answered on 07 Dec 2011, 08:38 AM
Hi,

 How the grid is bound is your case? Are you using RadDomainDataSource? You can simply create second data source without PageSize set and load the items from the service when needed. Still you should be careful since you may get communication exception if you try to serialize large collection on the client - in such case please check my suggestion in the first reply. 

Kind regards,
Vlad
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Mike
Top achievements
Rank 2
answered on 07 Dec 2011, 03:58 PM
No we're not using a RadDomainDataSource. Yes I gathered that I can pull the data from our RIA service into another data source for export. What I'm a bit foggy on is the mechanics of it. I can handle the Exporting event, but is that the appropriate place? The RIA load operation is asynchronous, do I create my own export dialog that selects the file and then does the export? Even though your demo is no longer available, could you send it to me since it will probably give me some idea of the correct approach without a bunch of ad hoc experimentation.

thanks,
Mike
0
Vlad
Telerik team
answered on 08 Dec 2011, 08:20 AM
Hi,

 All you need to do is to call Export() grid method in your RIA service load completed event handler with desired GridViewExportOptions. As you can see this is the exact reason why we've removed this demo -  it was just too trivial.

Kind regards,
Vlad
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
GridView
Asked by
lina fetisova
Top achievements
Rank 1
Answers by
Vlad
Telerik team
lina fetisova
Top achievements
Rank 1
Mike
Top achievements
Rank 2
Share this question
or