Browse Source

fix(excel): 解决Excel导出时工作表名称非法字符和长度限制问题

- 修复Excel工作表名称中包含非法字符\ / ? * [ ]导致的导出失败
- 添加工作表名称长度限制为31个字符的处理逻辑
- 更新英文翻译中的导出前缀文本格式
- 清理代码中的多余空行以提高可读性
- 简化导出函数中的参数格式化逻辑
master
qiankanghui 2 weeks ago
parent
commit
c2a6bdf7d9
  1. 2
      cclqms-vue/src/i18n/locales/qc.en.js
  2. 18
      cclqms-vue/src/utils/excel-util.js
  3. 9
      cclqms-vue/src/views/modules/qc/qcPartAttribute.vue

2
cclqms-vue/src/i18n/locales/qc.en.js

@ -976,7 +976,7 @@ module.exports = {
dataSyncConfirm: 'Run material catalog data sync?', dataSyncConfirm: 'Run material catalog data sync?',
dataSyncSuccess: 'Data sync completed', dataSyncSuccess: 'Data sync completed',
dataSyncFail: 'Data sync failed', dataSyncFail: 'Data sync failed',
exportPrefix: 'InspectionTemplateByMaterial',
exportPrefix: 'Inspection template by material',
exportHeader: 'Inspection template by material', exportHeader: 'Inspection template by material',
tableNameMain: 'Material attribute settings', tableNameMain: 'Material attribute settings',
tableNameTemplate: 'Inspection template list', tableNameTemplate: 'Inspection template list',

18
cclqms-vue/src/utils/excel-util.js

@ -155,7 +155,23 @@ let export2Excel = opt => {
} }
// console.log(ws); // console.log(ws);
const wb = XLSX.utils.book_new(); const wb = XLSX.utils.book_new();
XLSX.utils.book_append_sheet(wb, ws, options.fileName.replace(/\.xlsx/, ""));
// Excel sheet名称限制:最大31个字符,且不能包含 \ / ? * [ ]
let sheetName = options.fileName
.replace(/\.xlsx/, "")
.replace(/[\\\/\?\*\[\]]/g, "");
// 限制31字符
if (sheetName.length > 31) {
sheetName = sheetName.substring(0, 31);
}
XLSX.utils.book_append_sheet(
wb,
ws,
sheetName
);
XLSX.writeFile(wb, options.fileName); XLSX.writeFile(wb, options.fileName);
}); });
} }

9
cclqms-vue/src/views/modules/qc/qcPartAttribute.vue

@ -6640,13 +6640,12 @@ export default {
this.searchData.page = 1 this.searchData.page = 1
excel.exportTable({ excel.exportTable({
url: '/pms/qc/qcPartAttributeSearch', url: '/pms/qc/qcPartAttributeSearch',
columnMapping: this.columnList, //table
mergeSetting: [], //
columnMapping: this.columnList,
params: this.searchData, params: this.searchData,
fileName: this.exportName + '.xlsx', fileName: this.exportName + '.xlsx',
rowFetcher: (res) => res.data,
columnFormatter: [],
dropColumns: [],
rowFetcher: (res) => {
return res.data
},
}) })
}, },

Loading…
Cancel
Save