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

Adding a title to a Grid on Excel Export

3 Answers 235 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Mike Kacos
Top achievements
Rank 1
Mike Kacos asked on 27 Sep 2011, 04:11 PM
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

3 Answers, 1 is accepted

Sort by
0
Ivan Ivanov
Telerik team
answered on 30 Sep 2011, 01:08 PM
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 >>
0
Mike Kacos
Top achievements
Rank 1
answered on 30 Sep 2011, 03:32 PM
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
0
Ivan Ivanov
Telerik team
answered on 03 Oct 2011, 03:56 PM
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 >>
Tags
GridView
Asked by
Mike Kacos
Top achievements
Rank 1
Answers by
Ivan Ivanov
Telerik team
Mike Kacos
Top achievements
Rank 1
Share this question
or