【问题标题】:Bootstrap TableExport decimal issueBootstrap TableExport 十进制问题
【发布时间】:2016-06-16 05:28:39
【问题描述】:

我有一个显示员工数据的引导表,包括具有给定格式的工资单 ID:1606.xxxx

这是我的桌子的样子:

<table id="table_search"
    data-toggle="table"
    data-search="true"
    data-show-refresh="true"
    data-show-toggle="true"
    data-show-columns="true"
    data-show-export="true"
    data-minimum-count-columns="2"
    data-show-pagination-switch="true"
    data-pagination="true"
    data-page-list="[10, 25, 50, 100, ALL]"
    data-show-footer="false"
    data-export-data-type="all"
    data-export-types="['excel']">
    <thead>
        <tr>
            <th data-field="id">ID</th>
            <th data-field="payroll_id" >Payroll ID</th>
            <th data-field="nama_karyawan">Employee Name</th>
            <th data-field="level">Level</th>
            <th data-field="grade">Grade</th>
            <th data-field="title">Title</th>
            <th data-field="lokasi">Location</th>
            <th data-field="cost_sales">Cost Sales</th>
            <th data-field="dept">Department</th>
            <th data-field="div">Division</th>
            <th data-field="dir">Directorat</th>
            <th data-field="active_period">Active Period</th>
        </tr>
    </thead>
</table>

表格正确显示,但是当我使用 TableExport 插件将其导出到 excel 中时,它是这样的 exported results

如您所见,插件以某种方式将其视为带小数的数字,这正是我要避免的。我尝试评论可能是 tableExport js 文件中的原因的 parseNumber 函数,但结果总是相同

我做错了什么?

PS:我不希望文件导出后格式化,我希望它按原样导出数据。

【问题讨论】:

    标签: php jquery ajax excel bootstrap-table


    【解决方案1】:

    你可以使用

    ...
    <td data-tableexport-msonumberformat="\@">123.450</td>
    ...
    

    这样tableExport.js 将在创建HTMLExcel 导出时将mso-number-format: "\@" 用作TDstyle。这导致将单元格格式化为Text

    示例: http://jsfiddle.net/uqtubq5c/1/

    你也可以使用

    ...
    <td data-tableexport-msonumberformat="0.000">123.450</td>
    ...
    

    这导致 Excel 中的数字格式为 0.000。所以单元格内容仍然是一个数字,可以在进一步的计算中使用。 Text 在计算中使用时可能会导致问题。


    如果您不能将自己的data-tableexport-msonumberformat 属性设置为TD 元素,那么您可以扩展tableExport.jquery.plugin

    tableExport.js有:

    ...
          var defaults = {
            onMsoNumberFormat: onMsoNumberFormat,
    ...
    

    onMsoNumberFormat 必须是一个函数。

    如果函数onMsoNumberFormat是这样的:

    onMsoNumberFormat = function(cell, row, col) {
     if (row > 0 && col == 2) {
      return "#\\,##0\\.00";
     }
     if (row > 0 && col == 3) {
      return "\\@";
     }
    };
    

    然后从第 2 行 (row>0) 向上的第三列 (col==2) 将得到 style="mso-number-format:#\,##0\.00",从第 2 行 (row>0) 向上的第四列 (col==3) 将得到 @987654341 @。 @Textformat。

    示例: http://jsfiddle.net/uqtubq5c/3/

    【讨论】:

    • 我忘了提到我正在使用 JSON 回调填充表。我无法向 td 添加属性,因为我只是在定义 th..(我已经编辑了我的问题)。我尝试在回调成功时使用 jQuery 的 attr() 方法,但我无法使其工作
    • 查看我的补充。
    • 你是一个救生员!这个小提琴应该在引导表示例页面中
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-15
    • 1970-01-01
    • 2014-01-22
    • 1970-01-01
    • 1970-01-01
    • 2022-06-21
    • 1970-01-01
    相关资源
    最近更新 更多