当前位置: 首页 > 工具软件 > word-Table > 使用案例 >

关于bootstrap-table导出问题,table-export使用

吴峰
2023-12-01

1、导出文件为.xls文件,使用office2007及以上版本打开出现格式不兼容

解决方法:

  $('#table_id').tableExport({
            type: 'xlsx',
            exportDataType: "all",
            //表格工作区名称
            worksheetName: 'sheet1',
            ignoreColumn: [2],//忽略某一列的索引
            fileName: '下载文件名称' + Date.now(),//下载文件名称
            onCellHtmlData: function (cell, row, col, data) {
                return data;
            },
        });

2、设置为.xlsx格式之后,文件里的数据出现两位有效数字,统计人数出现小数,虽然为.00后缀,但看着也难受

查了好长时间,只查到一个直接改源码的解决方案,但是我下个文件导出万一想要保留两位小数该怎么做,还是去改源码吗?不行,于是自己去看了一下源码

const defaults 默认配置的mso,转化.xlsx格式的配置
mso: {                            // word或者excel
    fileFormat: 'xlshtml',        // 'xlshtml' = Excel 2000 html format
                                  // 'xmlss' = XML Spreadsheet 2003 file format (XMLSS)
                                  // 'xlsx' = Excel 2007 Office Open XML format
    onMsoNumberFormat: null,        // Excel 2000 html format only. See readme.md for more information about msonumberformat
    pageFormat: 'a4',               // 页面大小
    pageOrientation: 'portrait',    // portrait, landscape (xlshtml format only)
    rtl: false,                     // true = Set worksheet option 'DisplayRightToLeft'
    styles: [],                     // E.g. ['border-bottom', 'border-top', 'border-left', 'border-right']
    worksheetName: '',
    xlsx: {                         //xlsx设置
        formatId: {                   // XLSX format (id) used to format excel cells. See readme.md: data-tableexport-xlsxformatid
        date: 14,                   // The default format id, or a format string (e.g. 'm/d/yy'), or a function(cell, row, col)
        numbers: 2,                 // The default Format id, or a format string (e.g. '\"T\"\ #0.00'), or a function(cell, row, col)
        currency: 164               // This id is used by "data-tableexport-xlsxformatid" to allow you to export a cell in currency format (see below)
          },
        format: {
            currency: '$#,##0.00;[Red]-$#,##0.00' // The format string to be used for the export for the currency format 
                                                  // Euro format: '#,##0.00 €;[Red](#,##0.00) €'
          },
          onHyperlink: null             // function($cell, row, col, href, content, hyperlink): Return what to export for hyperlinks
   }
}
    
      

解决方案:

   $('#table_id').tableExport({
            type: 'excel',
            mso:{//格式转换,可以转换为excel与word
                fileFormat:'xlsx', //转换为excel的.xlsx格式文档,适用于Excel2007及以上版本
                xlsx:{//配置.xlsx文件的单元格内容格式
                    formatId:{
                        numbers:0 //保留小数点后的位数
                    }
                }
            } ,
            exportDataType: "all",
            //表格工作区名称
            worksheetName: 'sheet1',
            ignoreColumn: [2],//忽略某一列的索引
            fileName: '文件名称' + Date.now(),//下载文件名称
            onCellHtmlData: function (cell, row, col, data) {
                console.info(data);
                return data;
            },
        });

ps:还是早上思路清晰!

 类似资料: