diff --git a/aurelia-slickgrid/src/aurelia-slickgrid/services/controlAndPlugin.service.ts b/aurelia-slickgrid/src/aurelia-slickgrid/services/controlAndPlugin.service.ts index 09e002801..480198b46 100644 --- a/aurelia-slickgrid/src/aurelia-slickgrid/services/controlAndPlugin.service.ts +++ b/aurelia-slickgrid/src/aurelia-slickgrid/services/controlAndPlugin.service.ts @@ -16,6 +16,7 @@ import { import { ExportService } from './export.service'; import { FilterService } from './filter.service'; import { SortService } from './sort.service'; +import { sanitizeHtmlToText } from './../services/utilities'; import * as $ from 'jquery'; // using external non-typed js libraries @@ -163,7 +164,11 @@ export class ControlAndPluginService { if (!gridOptions.editable || !columnDef.editor) { const isEvaluatingFormatter = (columnDef.exportWithFormatter !== undefined) ? columnDef.exportWithFormatter : gridOptions.exportOptions.exportWithFormatter; if (columnDef.formatter && isEvaluatingFormatter) { - return columnDef.formatter(0, 0, item[columnDef.field], columnDef, item, this._grid); + const formattedOutput = columnDef.formatter(0, 0, item[columnDef.field], columnDef, item, this._grid); + if (columnDef.sanitizeDataExport || (gridOptions.exportOptions && gridOptions.exportOptions.sanitizeDataExport)) { + return sanitizeHtmlToText(formattedOutput); + } + return formattedOutput; } } diff --git a/aurelia-slickgrid/src/aurelia-slickgrid/services/export.service.ts b/aurelia-slickgrid/src/aurelia-slickgrid/services/export.service.ts index 67a94935f..8f5441a50 100644 --- a/aurelia-slickgrid/src/aurelia-slickgrid/services/export.service.ts +++ b/aurelia-slickgrid/src/aurelia-slickgrid/services/export.service.ts @@ -18,7 +18,7 @@ import { } from './../models/index'; import { TextEncoder } from 'text-encoding-utf-8'; // import { TextEncoder } from 'utf8-encoding'; -import { addWhiteSpaces, htmlEntityDecode } from './../services/utilities'; +import { addWhiteSpaces, htmlEntityDecode, sanitizeHtmlToText } from './../services/utilities'; import * as $ from 'jquery'; // using external non-typed js libraries @@ -226,7 +226,7 @@ export class ExportService { // does the user want to sanitize the output data (remove HTML tags)? if (columnDef.sanitizeDataExport || this._exportOptions.sanitizeDataExport) { - itemData = this.sanitizeHtmlToText(itemData); + itemData = sanitizeHtmlToText(itemData); } // when CSV we also need to escape double quotes twice, so " becomes "" @@ -250,7 +250,7 @@ export class ExportService { * @param itemObj */ readGroupedTitleRow(itemObj: any) { - let groupName = this.sanitizeHtmlToText(itemObj.title); + let groupName = sanitizeHtmlToText(itemObj.title); const exportQuoteWrapper = this._exportQuoteWrapper || ''; const delimiter = this._exportOptions.delimiter; const format = this._exportOptions.format; @@ -292,7 +292,7 @@ export class ExportService { // does the user want to sanitize the output data (remove HTML tags)? if (columnDef.sanitizeDataExport || this._exportOptions.sanitizeDataExport) { - itemData = this.sanitizeHtmlToText(itemData); + itemData = sanitizeHtmlToText(itemData); } if (format === FileType.csv) { @@ -308,17 +308,6 @@ export class ExportService { return output; } - /** - * Sanitize, return only the text without HTML tags - * @input htmlString - * @return text - */ - sanitizeHtmlToText(htmlString: string) { - const temp = document.createElement('div'); - temp.innerHTML = htmlString; - return temp.textContent || temp.innerText; - } - /** * Triggers download file with file format. * IE(6-10) are not supported diff --git a/aurelia-slickgrid/src/aurelia-slickgrid/services/utilities.ts b/aurelia-slickgrid/src/aurelia-slickgrid/services/utilities.ts index 7c293ddea..4cf81a1f7 100644 --- a/aurelia-slickgrid/src/aurelia-slickgrid/services/utilities.ts +++ b/aurelia-slickgrid/src/aurelia-slickgrid/services/utilities.ts @@ -328,6 +328,17 @@ export function parseUtcDate(inputDateString: string, useUtc: boolean): string | return date; } +/** + * Sanitize, return only the text without HTML tags + * @input htmlString + * @return text + */ +export function sanitizeHtmlToText(htmlString: string) { + const temp = document.createElement('div'); + temp.innerHTML = htmlString; + return temp.textContent || temp.innerText; +} + /** * Converts a string to camel case * @param str the string to convert diff --git a/aurelia-slickgrid/src/examples/slickgrid/example12.ts b/aurelia-slickgrid/src/examples/slickgrid/example12.ts index c4d3d4cae..2ba043e7b 100644 --- a/aurelia-slickgrid/src/examples/slickgrid/example12.ts +++ b/aurelia-slickgrid/src/examples/slickgrid/example12.ts @@ -98,11 +98,13 @@ export class Example12 { sidePadding: 15 }, enableAutoResize: true, + enableExcelCopyBuffer: true, enableFiltering: true, enableTranslate: true, exportOptions: { // set at the grid option level, meaning all column will evaluate the Formatter (when it has a Formatter defined) exportWithFormatter: true, + sanitizeDataExport: true }, gridMenu: { showExportCsvCommand: true, // true by default, so it's optional