Export to xlsx format issues

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

    Posted 13 Apr 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
    281 posts

    Posted 15 Apr 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. UI for WPF is Visual Studio 2017 Ready
Back to Top