Export not showing formatted data (SF 20.1.55)

In the following generic example, the Grid by default does not export the formatted contents:

<GridColumn HeaderText="@prop.Header" Width="60" Field="@prop.accessor"

                                              AutoFit="true" MinWidth="40" IsFrozen="@frozen" AllowFiltering="@filter">

                                                <Template>

                                                @{

 <span style="font-size:small;font-weight:600"> ... Custom label syntax here ... </span> <----- THIS IS NOT SHOWING IN EXPORT

}

</Template>

The results being exported are NOT the formatted column but instead the datasource

for the first cell it should have exported the following :

98 (43.2%)


4 Replies

TT tttrickyyy May 20, 2022 03:13 PM UTC

Also forgot to mention, I do have the template option set:

  ExcelExportProperties exportProperties = new ExcelExportProperties();

            exportProperties.IncludeTemplateColumn = true;




SP Sarveswaran Palani Syncfusion Team May 23, 2022 11:41 AM UTC

Hi Tricky,


Greetings from Syncfusion Support.


Query: "Export not showing formatted data"


We have analyzed your query and we suggest you to use ExcelQueryCellInfoEvent method to achieve your requirement. This event will be triggered when cell is created in excel sheet along with its value. using this event we can export the templated columns values of the DataGrid by defining the IncludeTemplateColumn of ExcelExportProperties as true.


Refer the below code example.


  public void ExcelQueryCellInfoHandler(ExcelQueryCellInfoEventArgs<Order> args)

    {

        if (args.Column.Field == "CustomerID")

        {

            args.Cell.Value = "Mr." + args.Data.CustomerID;

        }

    }



Note: ExcelQueryCellInfoEvent will be triggered for each and every cell in excel file.


We have already discussed this topic in our UG documentation. Kindly refer the documentation link shared.


https://blazor.syncfusion.com/documentation/datagrid/excel-exporting#export-template-columns


Please get back to us if you have further queries.


Regards,

Sarveswaran PK



TT tttrickyyy May 24, 2022 02:19 PM UTC

I was hoping for something that the tool would handle (rather than us having to rewrite the business logic). We'll try and implement this solution.



SP Sarveswaran Palani Syncfusion Team May 25, 2022 01:31 PM UTC

Hi Tricky,


Thanks for contacting Syncfusion Support again.


We have understood your query and want to inform that basically we can display whatever components, HTML elements in columns using Templated Columns. But it can’t be able to export directly from the column. That's why we use ExcelQueryCellInfoHandler events to export the templated column. Please try and implement using this event. If you have faced any issues, Please get back to us


Regards,

Sarveswaran PK


Loader.
Up arrow icon