【问题标题】:Can I format excel column after exporting using table export jquery plugin with bootstrap table我可以在使用带有引导表的表导出 jquery 插件导出后格式化 excel 列吗
【发布时间】:2020-12-14 18:06:22
【问题描述】:

我正在使用引导表在我的 Web 应用程序中显示一些数据。 https://bootstrap-table.com/ 并且我想添加一个导出功能。文档说要使用 https://github.com/hhurz/tableExport.jquery.plugin 所以我已将其添加到我的导入中并进行了必要的代码更改。在文档中,它说您可以通过在生成表格时应用可选的 html 数据属性来指定要导出的单元格的格式,但是如果我的表格是使用 bootstrap-table 生成的,我该怎么做。我似乎无法解决。我基本上需要将 html 数据属性 data-tableexport-msonnumberformat="0" 设置为由我的引导表 javascript 生成的一组 td。

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <link href="/webjars/bootstrap/4.5.3/css/bootstrap.min.css" rel="stylesheet">
    <script type="text/javascript" src="/webjars/jquery/3.5.1/jquery.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script type="text/javascript" src="/webjars/bootstrap/4.5.3/js/bootstrap.min.js"></script>
<link href="/webjars/bootstrap-table/1.16.0/bootstrap-table.css" rel="stylesheet"></script>
</head>

<body class="bg-light">
<button id="exportExcelBtn" class="btn btn-sm btn-success" type="button">
        Export 
    </button>
<table id="table"></table>

<script src="/webjars/bootstrap-table/1.16.0/bootstrap-table.min.js"></script>
<script src="/webjars/bootstrap-table/1.16.0/extensions/export/bootstrap-table-export.min.js"></script>
<script type="text/javascript" src="https://unpkg.com/tableexport.jquery.plugin/tableExport.min.js"></script>

<script type="text/javascript">
    $( document ).ready(function() {
        $('#exportExcelBtn').on('click', function () {
            $('#table').tableExport({
                type: 'excel',
                fileName: "Order Summary"
            });
        });
        $('#table').bootstrapTable({
            url: '/getTableData',
            columns: [
                {
                    field: 'orderNo',
                    title: 'Order No',
                    sortable: true
                },
                {
                    field: 'itemNo',
                    title: 'Item No',
                    sortable: true,
                    **tableExport: {msoNumberFormat: '0'}**
                }
        })

    });
</script>
</body>
</html>

【问题讨论】:

    标签: bootstrap-table


    【解决方案1】:

    https://github.com/himingby/tableExport.jquery.plugin/blob/master/test/index.html

    你能在下面试试这个吗?

    <script type="text/javascript">
    function DoOnMsoNumberFormat(cell, row, col) {
    var result = "";
    if (row > 0 && col === 0)
      result = "\\@";
    else if (row > 0 && col === 2)
      result = "0"; // #issue 327: Preserve long numbers
    return result;
    

    };

    $( document ).ready(function() {
        $('#exportExcelBtn').on('click', function () {
            $('#table').tableExport({
                type: 'excel',
                fileName: "Order Summary",
                mso:{onMsoNumberFormat: DoOnMsoNumberFormat},
            });
        });
        $('#table').bootstrapTable({
            url: '/getTableData',
            columns: [
                {
                    field: 'orderNo',
                    title: 'Order No',
                    sortable: true
                },
                {
                    field: 'itemNo',
                    title: 'Item No',
                    sortable: true
            
                }
        })
    
    });
    

    【讨论】:

      猜你喜欢
      • 2019-03-30
      • 2019-10-26
      • 1970-01-01
      • 2018-04-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-01
      相关资源
      最近更新 更多