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

18 posts, 0 answers
  1. lina fetisova
    lina fetisova avatar
    110 posts
    Member since:
    Apr 2010

    Posted 02 Aug 2010 Link to this post

    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?
  2. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 02 Aug 2010 Link to this post

    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
  3. DevCraft banner
  4. lina fetisova
    lina fetisova avatar
    110 posts
    Member since:
    Apr 2010

    Posted 02 Aug 2010 Link to this post

    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?
  5. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 02 Aug 2010 Link to this post

    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
  6. lina fetisova
    lina fetisova avatar
    110 posts
    Member since:
    Apr 2010

    Posted 02 Aug 2010 Link to this post

    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?
  7. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 02 Aug 2010 Link to this post

    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
  8. lina fetisova
    lina fetisova avatar
    110 posts
    Member since:
    Apr 2010

    Posted 02 Aug 2010 Link to this post

    Vlad, info about the installer:

    This installer database contains the logic and data required to install Telerik RadControls for Silverlight Q3 2009 SP2.
  9. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 03 Aug 2010 Link to this post

    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
  10. Mike
    Mike avatar
    32 posts
    Member since:
    May 2011

    Posted 06 Dec 2011 Link to this post

    Your demo seems to be broken. Silverlight loads but nothing is displayed. 

    Mike
  11. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 06 Dec 2011 Link to this post

    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 >>

  12. Mike
    Mike avatar
    32 posts
    Member since:
    May 2011

    Posted 06 Dec 2011 Link to this post

    So is there a demo/code snippet that shows how to export all data for a paged collection data source?

    Mike
  13. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 06 Dec 2011 Link to this post

    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 >>

  14. Mike
    Mike avatar
    32 posts
    Member since:
    May 2011

    Posted 06 Dec 2011 Link to this post

    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
  15. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 06 Dec 2011 Link to this post

    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 >>

  16. Mike
    Mike avatar
    32 posts
    Member since:
    May 2011

    Posted 06 Dec 2011 Link to this post

    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
  17. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 07 Dec 2011 Link to this post

    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 >>

  18. Mike
    Mike avatar
    32 posts
    Member since:
    May 2011

    Posted 07 Dec 2011 Link to this post

    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
  19. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 08 Dec 2011 Link to this post

    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 >>

Back to Top
DevCraft banner