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. 22
      cclqms-vue/src/utils/excel-util.js
  3. 17
      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',

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

@ -154,9 +154,25 @@ let export2Excel = opt => {
setStyle(ws, merges); setStyle(ws, merges);
} }
// console.log(ws); // console.log(ws);
const wb = XLSX.utils.book_new();
XLSX.utils.book_append_sheet(wb, ws, options.fileName.replace(/\.xlsx/, ""));
XLSX.writeFile(wb, options.fileName);
const wb = XLSX.utils.book_new();
// 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);
}); });
} }

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

@ -373,7 +373,7 @@
</el-select> </el-select>
</el-form-item> </el-form-item>
</el-col> </el-col>
<el-col :span="12"> <el-col :span="12">
<el-form-item :label="$t('qc.partAttributePage.dieMoldFlag')"> <el-form-item :label="$t('qc.partAttributePage.dieMoldFlag')">
<el-input v-model="dieMoldAddData.handle" disabled></el-input> <el-input v-model="dieMoldAddData.handle" disabled></el-input>
@ -412,7 +412,7 @@
</el-col> </el-col>
</el-row> </el-row>
<el-row :gutter="20"> <el-row :gutter="20">
<el-col :span="24"> <el-col :span="24">
<el-form-item :label="$t('qc.table.remark')"> <el-form-item :label="$t('qc.table.remark')">
<el-input type="textarea" :rows="2" v-model="dieMoldAddData.remark" clearable></el-input> <el-input type="textarea" :rows="2" v-model="dieMoldAddData.remark" clearable></el-input>
@ -942,7 +942,7 @@
</el-table-column> </el-table-column>
</el-table> </el-table>
</el-tab-pane> </el-tab-pane>
<!-- 文件采集配置 --> <!-- 文件采集配置 -->
<el-tab-pane :label="$t('qc.partAttributePage.tabFileCollect')" name="fileCollect"> <el-tab-pane :label="$t('qc.partAttributePage.tabFileCollect')" name="fileCollect">
<el-form label-position="top" style="margin-left: 2px;"> <el-form label-position="top" style="margin-left: 2px;">
@ -4949,7 +4949,7 @@ export default {
}, },
openQcSpecWarningDialog(row) { openQcSpecWarningDialog(row) {
this.qcSpecWarningCurrentRow = row this.qcSpecWarningCurrentRow = row
this.qcSpecWarningList = [] this.qcSpecWarningList = []
this.qcSpecWarningDialogFlag = true this.qcSpecWarningDialogFlag = true
this.loadQcSpecWarningDictOptions().then(() => { this.loadQcSpecWarningDictOptions().then(() => {
@ -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