Adding a title to a Grid on Excel Export

4 posts, 0 answers
  1. Mike Kacos
    Mike Kacos avatar
    28 posts
    Member since:
    Sep 2009

    Posted 27 Sep 2011 Link to this post

    Hi,
       I need to add a title above the header row of a grid when exporting to Excel.  So we need to have "For Official Use Only" appear in any Excel Worksheet that is created as a result of exporting from a Grid.  I've seen some examples, but they seem to only work if the format used for export is HTML.  We need to use ExcelML as seen here:

    protected override void OnClick()
            {
                base.OnClick();
     
                try
                {
     
                    
                    string extension = "";
                    extension = "xml";
     
                    SaveFileDialog dialog = new SaveFileDialog();
                    dialog.DefaultExt = extension;
     
                    dialog.Filter = String.Format( "{1} files (*.{0})|*.{0}|All files (*.*)|*.*", extension, "Excel" );
                    dialog.FilterIndex = 1;
     
                    if (dialog.ShowDialog() == true)
                    {
                        using (Stream stream = dialog.OpenFile())
                        {
                            GridViewExportOptions exportOptions = new GridViewExportOptions();
                            exportOptions.Format = ExportFormat.ExcelML;
                            exportOptions.ShowColumnFooters = true;
                            exportOptions.ShowColumnHeaders = true;
                            exportOptions.ShowGroupFooters = false;
     
                            GridToExport.Export( stream, exportOptions );
                             
                        }
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
     
            }

    Is there a way to accomplish this, using this export format?

    Thanks,
    Mike
  2. Ivan Ivanov
    Admin
    Ivan Ivanov avatar
    1216 posts

    Posted 30 Sep 2011 Link to this post

    Hello Mike Kacos,

    The approach while exporting to ExcelML is pretty much the same. I have prepared an example project that illustrates how to achieve this.

    Kind regards,
    Ivan Ivanov
    the Telerik team
    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
  3. Mike Kacos
    Mike Kacos avatar
    28 posts
    Member since:
    Sep 2009

    Posted 30 Sep 2011 Link to this post

    Thank you for the response and example project.  The example project works great, yet when I copy the code into my project, I have a slightly different result.  In the example project output, I see the title on the first row, then the headers with filter drop downs on the second row.  When I use the same code in my project however, I still have the title on the first row, and the headers on the second row, but the filter drop downs are still on the first row with the title and the rest of the columns on row 1 which are all blank.

    Is it possible there is a difference with the underlying XAML that could cause this?  I think we're very close, however I can't quite get there yet.

    Thanks, Mike
  4. Ivan Ivanov
    Admin
    Ivan Ivanov avatar
    1216 posts

    Posted 03 Oct 2011 Link to this post

    Hi Mike Kacos,

    Most of the custom exporting scenarios fall back to raw string processing, which makes code fragments inappropriate for direct reuse. Please, refer to this line from my source:
    msStr = msStr.Replace("R1C1:R1C3", "R2C1:R2C3");
    It is meant to reposition the autofilter cells in your worksheet. However, I believe that you have a different cell range in your scenario and you should specify it, in order to make things work.

    Kind regards,
    Ivan Ivanov
    the Telerik team
    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
Back to Top