虽然可以打开看到里面的内容,但是给人的感觉就是很不爽,于是分析下代码找到了解决方法
找到文件public/assets/libs/bootstrap-table/dist/extensions/export/bootstrap-table-export.js
大概在97行
把代码
require(['tableexport'], function () {
that.$el.tableExport($.extend({}, that.options.exportOptions, {
type: type,
escape: false
}));
});
替换成
if(type == 'excel'){
require(['tableexport','/assets/libs/tableExport.jquery.plugin/libs/js-xlsx/xlsx.core.min.js'], function () {
that.$el.tableExport($.extend({}, that.options.exportOptions, {
type:'excel',
mso: { fileFormat: 'xlsx' }
}));
});
}else{
require(['tableexport'], function () {
that.$el.tableExport($.extend({}, that.options.exportOptions, {
type: type,
escape: false
}));
});
}
这里需要引入文件
/assets/libs/tableExport.jquery.plugin/libs/js-xlsx/xlsx.core.min.js
所以可以去https://github.com/hhurz/tableExport.jquery.plugin下载引入
后端引入的是压缩包文件,所以这里需要把文件public/assets/libs/bootstrap-table/dist/extensions/export/bootstrap-table-export.js压缩成public/assets/libs/bootstrap-table/dist/extensions/export/bootstrap-table-export.min.js文件
最后需要在网站根路径命令窗口下执行php think min -m all -r all
针对fastadmin版本1.6.1.20250430 的写法如下
require(['tableexport','/assets/libs/tableExport.jquery.plugin/libs/js-xlsx/xlsx.core.min.js'], function () {
var type = $(li).data('type'),doExport ;
console.log(type);
if(type == 'excel'){
doExport = function () {
that.$el.tableExport($.extend({}, that.options.exportOptions, {
type:'excel',
mso: { fileFormat: 'xlsx' }
}));
};
}else{
doExport = function () {
that.$el.tableExport($.extend({}, that.options.exportOptions, {
type: type,
escape: false
}));
};
}
console.log(doExport);
if (that.options.exportDataType === 'all' && that.options.pagination) {
that.$el.one(that.options.sidePagination === 'server' ? 'post-body.bs.table' : 'page-change.bs.table', function () {
doExport();
that.togglePagination();
});
that.togglePagination();
} else if (that.options.exportDataType === 'selected') {
var data = that.getData(),
selectedData = that.getAllSelections();
// Quick fix #2220
if (that.options.sidePagination === 'server') {
data = {total: that.options.totalRows};
data[that.options.dataField] = that.getData();
var Table = typeof require === 'function' ? require('table') : null;
selectedData = {total: that.options.totalRows};
selectedData[that.options.dataField] = Table && that.options.maintainSelected ? Table.api.selecteddata(that.$el) : that.getAllSelections();
}
that.load(selectedData);
doExport();
that.load(data);
} else {
doExport();
}
});
可以使用 PHP 内置的 fputcsv() 函数将 2 维数组写入 CSV 文件,同时设置文件编码为 UTF-8 以避免中文乱码。示例代码如下:// 创建一个包含中文的 2 维数组$data = a...
具体上代码:// 导入 public function import(){ $file = $this->request->request('file'); ...
// $val = $currentSheet->getCellByColumnAndRow($currentColumn, $currentRow)->getValue();// ...
在不进行特殊设置的情况下,phpExcel将读取的单元格信息保存在内存中,我们可以通过PHPExcel_Settings::setCacheStorageMethod()来设置不同的缓存方式,已达到降...