Syncfusion Essential JS2 网格在导出到 MS Excel 2016 时显示带有 URL 的 HTML 标签

Syncfusion Essential JS2 grid reveals HTML tags with URLs in exporting to MS Excel 2016

我已经使用 syncfusion-ej2 网格 (https://ej2.syncfusion.com/16.1.32/angular/documentation/grid/) 实现了导出到 excel 的功能。网格中有一列包含 URL。导出完成后,这些链接将以 HTML 语法显示在 excel sheet 上。我已经在互联网上搜索过这个并且找不到任何解决方案。请指教

我们建议您使用Grid的“excelQueryCellInfo”事件。在“excelQueryCellInfo”事件处理函数中,我们移除了单元格数据中包含的锚标记,只将要导出的文本内容传递给excel。请参考下面的代码示例,

[html]    

<ejs-grid #masterGrid [dataSource]='data' ... [allowExcelExport]='true' (excelQueryCellInfo)='excelQueryCellInfo($event)'>
    ...
</ejs-grid>

[ts]

excelQueryCellInfo(args:any):void{
  if(args.column.field == "CustomerID"){        //Check for the “CustomerID” column which has the anchor data 
    let container:any = document.createElement("div");
    container.innerHTML = args.value;
    args.value = container.textContent;          //Pass only the string content to be exported to excel
  }
}

为方便起见,我们还准备了样本。请参考下面的link, 示例:https://stackblitz.com/edit/angular-srzcxu-41noip?file=normal-edit.component.ts

文档:https://ej2.syncfusion.com/angular/documentation/grid/api-gridComponent.html#excelquerycellinfo

马杜 [Syncfusion 团队]