Export to xlsx format issues

9 posts, 0 answers
  1. Viksit
    Viksit avatar
    1 posts
    Member since:
    Mar 2016

    Posted 13 Apr 2016 Link to this post

    I am using GridView's export functionality of 2016.1.217.45 version, see below the code snippet.
    string extension = "xls";
              SaveFileDialog dialog = new SaveFileDialog()
              {
                DefaultExt = extension,
                Filter = String.Format("{1} files (*.{0})|*.{0}|All files (*.*)|*.*", extension, "Excel"),
                FilterIndex = 1
              };
              if (dialog.ShowDialog() == true)
              {
                using (Stream stream = dialog.OpenFile())
                {
                  m_oGridView.Export(stream,
                   new GridViewExportOptions()
                   {
                     Format = ExportFormat.Xlsx,
                     ShowColumnHeaders = true,
                     ShowColumnFooters = false,
                     ShowGroupFooters = false,
                   });
                }
              }

     

    Following are the issues observed, please provide solutions or workarounds:

    1. The first row in the grid is not getting exported as second row in excel, instead it is appearing in the first row of excel after the row headers. See the snapshots - "GridUISnapshot.JPG" and "ExcelSnapshot.JPG".
    2. If the users specifies the extension of the file as ".xlsx", it is getting exported but not able to open in excel 2016 version, the error message is shown in the snapshot - "XlsxExtensionOpenError.JPG".  Since in File save dialog, user can specify .xlsx extension as well. In code we are specifying the format to be exported is xlsx, but still it is not compatible.

    Thanks,

    Viksit

  2. Stefan Nenchev
    Admin
    Stefan Nenchev avatar
    534 posts

    Posted 15 Apr 2016 Link to this post

    Hello Viksit,

    Thank you for the code implementation and the pictures provided.

    There seems to be an issue in the way you have set the export mechanism at your end. I have tested your exact implementation and indeed the behavior you explain is observed. However, it seems like you have mixed the Export and ExportToXlsx methods. Have in mind that there is a separate ExportToXlsx method that you can use. Though the approach is explained in the documentation, I am here adding it for your reference:

    private void btnExport_Click(object sender, RoutedEventArgs e)
    {
        string extension = "xlsx";
     
        SaveFileDialog dialog = new SaveFileDialog()
        {
            DefaultExt = extension,
            Filter = String.Format("{1} files (*.{0})|*.{0}|All files (*.*)|*.*", extension, "Excel"),
            FilterIndex = 1
        };
     
        if (dialog.ShowDialog() == true)
        {
            using (Stream stream = dialog.OpenFile())
            {
                gridViewExport.ExportToXlsx(stream,
                    new GridViewDocumentExportOptions()
                    {
                        ShowColumnFooters = true,
                        ShowColumnHeaders = true,
                        ShowGroupFooters = true
                    });
            }
        }
    }

    Bare in mind that this method requires some additional assembly references as well. You can find them at the beginning of the article.

    We are aware that the information provided in the whole section for exporting RadGridView is to some extend confusing. We are currently in the process of updating it and it should be live on our documentation page soon.

    Regards,
    Stefan Nenchev
    Telerik
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
  3. Flemming
    Flemming avatar
    5 posts
    Member since:
    Aug 2015

    Posted 23 May in reply to Stefan Nenchev Link to this post

    But this new ExportToXlsx removes doublet rows. I have tried all sort of settings, still same issue.

  4. Stefan
    Admin
    Stefan avatar
    791 posts

    Posted 26 May Link to this post

    Hi Flemming,

    Can you please clarify whether you are populating RadGridView with duplicated items? Note, that such an approach is generally not recommended as the control is not meant to be used in such manner.

    Best Regards,
    Stefan X1
    Progress Telerik
    Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
  5. Flemming
    Flemming avatar
    5 posts
    Member since:
    Aug 2015

    Posted 26 May in reply to Stefan Link to this post

    That's exactly what I am doing. And the export with these settings:

    using (Stream stream = dialog.OpenFile())
                    {
                        dg_Data.Export(stream,
                         new GridViewExportOptions()
                         {
                             Items = rdp_Data.Source,
                             Format = ExportFormat.ExcelML,
                             ShowColumnHeaders = true,
                         });
                    }

     

    This works, most of the time. It always make you have to get past a popup when you open the file and on some computer it just can't open. That's why I would like to use the new way.

  6. Stefan
    Admin
    Stefan avatar
    791 posts

    Posted 29 May Link to this post

    Hi Flemming,

    Though I am not completely sure why the popup is not displayed on some machines, I doubt that using the newer export mechanism would make any difference. The approach of using the two mechanisms would be basically the same. Also, as mentioned in my previous reply, populating RadGridView with duplicated data is not recommended.

    Best Regards,
    Stefan X1
    Progress Telerik
    Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
  7. Flemming
    Flemming avatar
    5 posts
    Member since:
    Aug 2015

    Posted 29 May in reply to Stefan Link to this post

    The old way, when it Works, gives you a popup that you have to say yes to. The new version seems to always work but has the duplicate problem. I think my solution must be the new version where I make sure I always have a unique field. Please fix that. Being able to handle duplicate fields should be a basic feature. At least give us the option :)
  8. Stefan
    Admin
    Stefan avatar
    791 posts

    Posted 01 Jun Link to this post

    Hi Flemming,

    As stated in my previous reply, populating RadGridView with duplicated items is not recommended. Moreover, as the data engine of the control is not designed to be used in such manner, I am afraid that we cannot commit ourselves to modifying it. Such implementation would require major modifications of the core functionalities of the control and will eventually result in a breaking change. With this in mind, avoiding the usage of duplicate items is the only solution we can provide.

    Best Regards,
    Stefan X1
    Progress Telerik
    Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
  9. Flemming
    Flemming avatar
    5 posts
    Member since:
    Aug 2015

    Posted 02 Jun in reply to Stefan Link to this post

    Ok thank you.

Back to Top