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

Upgrading 2013Q1 to 2018Q3: GridViewElementExportingEventArgs.Attributes\Styles

6 Answers 19 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Nir
Top achievements
Rank 1
Nir asked on 13 Nov 2018, 02:20 PM

Hi,

We are looking into upgrading our Telerik UI for WPF 2013Q1 to 2018Q3.

As part of the POC process I encountered the following blocking issue.

I need to upgrade this code to Telerik UI for WPF 2018 Q3 but wasn't able to do so after consulting the documentation available on the web.

The main issue is converting the removed\obsolete GridViewElementExportingEventArgs.Attributes["border"] and GridViewElementExportingEventArgs.Styles["background-color"] from 2013Q1 to 2018Q3.

 

Can you help me solve this upgrade blocking issue?

 

Thanks in advance

01.private static RadDocument CreateDocument(RadGridView grid, PrintSettings settings)
02.        {
03.            RadDocument document = null;
04. 
05.            using (var stream = new MemoryStream())
06.            {
07.                EventHandler<GridViewElementExportingEventArgs> elementExporting = (s, e) =>
08.                {
09.                    if (e.Element == ExportElement.Table)
10.                    {
11.                        e.Attributes["border"] = "0";
12.                    }
13.                    else if (e.Element == ExportElement.HeaderRow)
14.                    {
15.                        if (settings.HeaderBackground != null)
16.                        {
17.                            e.VisualParameters
18.                            e.Styles.Add("background-color", settings.HeaderBackground.ToString().Remove(1, 2));
19.                        }
20.                    }
21.                    else if (e.Element == ExportElement.GroupHeaderRow)
22.                    {
23.                        if (settings.GroupHeaderBackground != null)
24.                        {
25.                            e.Styles.Add("background-color", settings.GroupHeaderBackground.ToString().Remove(1, 2));
26.                        }
27.                    }
28.                    else if (e.Element == ExportElement.Row)
29.                    {
30.                        if (settings.RowBackground != null)
31.                        {
32.                            e.Styles.Add("background-color", settings.RowBackground.ToString().Remove(1, 2));
33.                        }
34.                    }
35.                };
36. 
37.                grid.ElementExporting += elementExporting;
38. 
39.                grid.Export(stream, new GridViewExportOptions()
40.                {
41.                    Format = Telerik.Windows.Controls.ExportFormat.Html,
42.                    ShowColumnFooters = grid.ShowColumnFooters,
43.                    ShowColumnHeaders = grid.ShowColumnHeaders,
44.                    ShowGroupFooters = grid.ShowGroupFooters
45.                });
46. 
47.                grid.ElementExporting -= elementExporting;
48. 
49.                stream.Position = 0;
50. 
51.                document = new HtmlFormatProvider().Import(stream);
52.            }
53. 
54.            return document;
55.        }

6 Answers, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 16 Nov 2018, 09:28 AM
Hi Nir,

Thank you for the provided code snippet.

Indeed, we made some changes in the API in order to provide extended styling capabilities of the exported data. You should be able to apply the needed customization by type casting the VisualParameters property of the event arguments of the ElementExporting event to GridViewHtmlVisualExportParameters. The approach is demonstrated in details in the ExportFormat.Html and Export topics. Can you please check them out?

Regards,
Stefan
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Nir
Top achievements
Rank 1
answered on 18 Nov 2018, 09:16 AM

Dear Stefan,

 

Thank you for your reply and link to the knowledge base pages.

Unfortunately I read those pages between my original answer and your reply and they did not solve my main issue with setting the border attribute.

I do use them for the background attribute.

I'm also having hard time finding all the applicable visual export parameter classes for the different export formats.

I was able to map the following formats:

* HTML: GridViewHtmlVisualExportParameters

* ExcelML: GridViewExcelMLVisualExportParameters

I was unable to locate the export parameter class that corresponds to:

*Xlsx

*Pdf

 

 

My main concern and blocking issue however is the border attribute, if I can solve this issue than the rest of the formats become low-priority and non-blocking.

 

Thank you in advance,

     Nir

 

 

0
Accepted
Stefan
Telerik team
answered on 21 Nov 2018, 05:36 PM
Hello Nir,

Thank you for the update.

The Xlsx and Pdf  export mechanisms raise the ElementExportingToDocument and ElementExportedToDocument events. The VisualParameters for both ExportToXlsx and ExportToPdf methods are of type GridViewDocumentVisualExportParameters. They expose the a Style property which is of type CellSelectionStyle. Through it you can set the CellBorders property to achieve your goal. Please, take a look at the Export Events for further reference.

Regards,
Stefan
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Nir
Top achievements
Rank 1
answered on 22 Nov 2018, 12:30 PM

Dear Stefan,

 

Thank you very much for your reply - it helped a lot.

Am I correct in assuming that using the code in line #8 below is equivalent to the old code in line #9 below?

01.EventHandler<GridViewElementExportingEventArgs> elementExporting = (s, e) =>
02.{
03.    GridViewHtmlVisualExportParameters visualParameters = e.VisualParameters as GridViewHtmlVisualExportParameters;
04.    if (visualParameters != null)
05.    {
06.        if (e.Element == ExportElement.Table)
07.        {
08.            visualParameters.Attributes["border"] = "0"; //new code using telerik 2018
09.            //e.Attributes["border"] = "0"; //old code using telerik 2013
10.        }
0
Accepted
Stefan
Telerik team
answered on 26 Nov 2018, 04:38 PM
Hi Nir,

Indeed, in regards to GridViewHtmlVisualExportParameters this approach would be the accurate one.

Regards,
Stefan
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Nir
Top achievements
Rank 1
answered on 27 Nov 2018, 10:35 AM
Thank you very much for your assistance.
Tags
GridView
Asked by
Nir
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Nir
Top achievements
Rank 1
Share this question
or