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

Cells with HTML value in Excel Export?

8 Answers 557 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Brian Roth
Top achievements
Rank 1
Brian Roth asked on 05 Dec 2014, 04:13 PM
I have a few cells in a grid where the value contains HTML strings.   As an example, we bold part of a string like "This item costs <b>$100<b>".  When we export to Excel, that cell displays the full HTML string.  Do you know if there's a way through the api that we can tell that cell to render as HTML so that the <b> tags don't show up and the text is properly bolded?  Thanks!

Regards,
Brian

8 Answers, 1 is accepted

Sort by
0
Alexander Popov
Telerik team
answered on 09 Dec 2014, 10:32 AM
Hi Brian,

Exporting cells containing HTML is not supported, as mentioned in the documentation. I would recommend checking this example, illustrating a possible workaround using the excelExport event.

Regards,
Alexander Popov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Brian Roth
Top achievements
Rank 1
answered on 10 Dec 2014, 05:16 PM
Hi Alexander,

Thanks for the reply.  This was helpful.  I still haven't figured out a way to only bold part of a value, but I'll keep looking.

Regards,
Brian
0
Frank
Top achievements
Rank 1
answered on 17 Oct 2017, 06:50 PM

Hi, quick question, is the above still not supported?

we have the same situation. there are cells with html tags that are showing nicely in grid but for Excel export we have to remove the tags. except that user needs to see part of the cell's text in bold. 

Regards,

Frank J.

 

0
Stefan
Telerik team
answered on 19 Oct 2017, 06:46 AM
Hello, Frank,

This can be achieved using custom logic on the excelExport event as suggested.

We have new examples for taking only the text from the HTML tags. It is for the footer template, but the same approach is valid for the cells as well:

https://docs.telerik.com/kendo-ui/knowledge-base/export-only-the-text-from-the-grid-cell-which-contains-html

Also, the bold style can be added using the custom styles:

https://docs.telerik.com/kendo-ui/framework/excel/appearance#configuration-options

I hope this is helpful.

Regards,
Stefan
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
John
Top achievements
Rank 1
answered on 30 Dec 2019, 06:19 AM

https://docs.telerik.com/kendo-ui/knowledge-base/export-only-the-text-from-the-grid-cell-which-contains-html

Hi,

I also have the same issue, my grid display paragraph content with html tags. if part of paragraph bold, it display correctly in grid and also in export PDF. but not in export excel.

 { field: "UnitPrice", title: "Price", template: '<b>Price</b>: #: kendo.format("{0:c}", UnitPrice)#' }

the above link only give the template value. even, if i bold the Price text, it display correctly with bold in grid but in export excel , it display as <b>Price:</b>.

 

0
Alex Hajigeorgieva
Telerik team
answered on 30 Dec 2019, 12:34 PM

Hi, John,

The article that you reference shows how to remove arbitrary HTML from the XML which could otherwise break it. It seems that you would like to do the opposite - show the column in the excel file as bold text, please correct me if I am wrong.

To better understand what goes on - the grid is a UI component which visualizes the data in its data source. The excel export does a similar thing - it exports the underlying data, it does not process arbitrary content in templates:

https://docs.telerik.com/kendo-ui/controls/data-management/grid/export/excel-export#known-limitations

The formats that are used in the workbook, follow the Microsoft formats and I did not find a way to include bold text within it:

https://support.office.com/en-us/article/number-format-codes-5026bbd6-04bc-48cd-bf33-80f18b4eae68

You could use the excelExport event to add another Column and make the Price text bold by using the sheets.rows.cells.bold property or you could bold the entire value:

https://dojo.telerik.com/@bubblemaster/EkOSOdix/2

  excelExport: function(e) {
    var sheet = e.workbook.sheets[0];
    for (var i = 1; i < sheet.rows.length; i++) {
      var row = sheet.rows[i];
      row.cells[1].format = ' " Price" $0.00;'
      row.cells[1].bold = true;
    }
  }

Let me know in case you have further questions.

Kind Regards,
Alex Hajigeorgieva
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
John
Top achievements
Rank 1
answered on 30 Dec 2019, 01:36 PM

Hi,

Thanks for the reply.

But the cells.bold property is bold the entire cell content.

But we dont need that. For example, my cell contains line like below:

"Oats’ momentum in Greece is bold and growing. Today, thanks to Quaker’s strong brand and consistent strategy, many new products entering the market contain oats and try to communicate vocally on the goodness of oats."

 

Here, I want to bold the text Oats and Quakers in gird and also in export excel.

so my content would be as below

"<b>Oats’<b> momentum in Greece is bold and growing. Today, thanks to <b>Quaker’s</b> strong brand and consistent strategy, many new products entering the market contain oats and try to communicate vocally on the goodness of oats."

This displaying correctly with bold property in grid as below

"Oats’ momentum in Greece is bold and growing. Today, thanks to Quaker’s strong brand and consistent strategy, many new products entering the market contain oats and try to communicate vocally on the goodness of oats."

but in excel, it display as below

"<b>Oats’<b> momentum in Greece is bold and growing. Today, thanks to <b>Quaker’s</b> strong brand and consistent strategy, many new products entering the market contain oats and try to communicate vocally on the goodness of oats.".

So I want in excel how it is in grid. could you please provide any solution for this?

0
Alex Hajigeorgieva
Telerik team
answered on 31 Dec 2019, 01:32 PM

Hi, John,

I understand the requirement is to bold part of the cell but I did not find a way that Microsoft Excel have allowed for this to be configured:

https://support.office.com/en-us/article/number-format-codes-5026bbd6-04bc-48cd-bf33-80f18b4eae68

The format of the cell is proprietary to the Excel cell and it is Excel that interprets how to show the cell. If you can find a way to do that with Excel custom numeric formatting - i.e bold part of the cell, then that should be used to pass to the Kendo UI Workbook cell.

If Microsoft did not implement such conditional custom formatting, then the alternative would be to insert a separate column with the bold text and next to it have the regular text:

Here is a test example for your reference:

https://dojo.telerik.com/EMeKetEr/2

Kind Regards,
Alex Hajigeorgieva
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.
Tags
Grid
Asked by
Brian Roth
Top achievements
Rank 1
Answers by
Alexander Popov
Telerik team
Brian Roth
Top achievements
Rank 1
Frank
Top achievements
Rank 1
Stefan
Telerik team
John
Top achievements
Rank 1
Alex Hajigeorgieva
Telerik team
Share this question
or