移除< span>从XLS导出列 [英] Remove <span> from column on XLS export

查看:172
本文介绍了移除< span>从XLS导出列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个工作的jQuery DataTable( https://www.datatables.net/ )使用TableTools在其中一列的每一行中插入< span> 元素。

I have a working jQuery DataTable (https://www.datatables.net/) using the TableTools plug-in with <span> elements in every row of one of the columns.

点击导出按钮,我想从导出的文件中隐藏/删除< span> 元素。不删除整个列,但只删除该列中的< span> 元素。

On clicking the export button, I would like to hide/remove the <span> elements from the exported file. Not remove the whole columns, but just the <span> elements within that column.

如何实现这个?我了解如何从导出中删除整个列,但是我没有找到一种从导出中删除特定元素的方法。

How can I achieve this? I understand how to remove an entire column from the export, but I have not found a way to remove particular elements from the export.

谢谢

更新

    "oTableTools": {
        "sSwfPath": "/public/swf/copy_csv_xls_pdf.swf",
        "aButtons": [
            {
                "sExtends": "print",
            },
            {
                "sExtends": "copy",
            },
            {
                "sExtends": "csv",                   
                "fnCellRender": function ( sValue, iColumn, nTr, iDataIndex ) {
                    return sValue;
                 }               
            }
        ]
      }

fnCellRender 到位,我只是不知道最好的方法是删除< span>

I have the fnCellRender in place, I'm just not sure what the best way is to strip out <span> elements.

推荐答案

在我的测试中,最新的TableTools已经在CSV文件中剥离了HTML标签。请参阅此示例

In my tests, latest TableTools already strips HTML tags in CSV file. See this example.

为了使其正常工作,您需要删除 fnCellRender 。显然,如果 fnCellRender 存在,TableTools默认情况下不会执行HTML剥离。

In order for this to work you need to remove fnCellRender. Apparently, if fnCellRender is present, TableTools doesn't do HTML stripping by default.

此外,尽管DataTables尝试要自动确定列数据类型,您可能需要考虑将列类型设置为 html 用于搜索和过滤。

Also, although DataTables tries to determine column data type automatically, you may want to consider setting that column type to html for searching and filtering.

从手册中:


在客户端处理模式下操作时,DataTables可以处理
用于每个单元格中显示的数据,该手册适用于执行操作的
手册。例如, HTML标签将从用于过滤器匹配的字符串中删除
,而排序格式可以
删除货币符号,以允许货币值按数字排序

When operating in client-side processing mode, DataTables can process the data used for the display in each cell in a manual suitable for the action being performed. For example, HTML tags will be removed from the strings used for filter matching, while sort formatting may remove currency symbols to allow currency values to be sorted numerically.

数据表有许多内置类型,自动
检测

DataTables has a number of built in types which are automatically detected:

...

html - HTML标签的基本字符串处理

html - Basic string processing for HTML tags


  • 排序 - 已移除HTML标记排序

  • 过滤 - 从过滤字符串中删除的HTML标记

这篇关于移除&lt; span&gt;从XLS导出列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆