|
|
@@ -2144,20 +2144,43 @@ const handleDelete = () => {
|
|
|
}
|
|
|
|
|
|
// 导出
|
|
|
-const exportExcel = ()=>{
|
|
|
+const exportExcel = () => {
|
|
|
const el = document.getElementById('table');
|
|
|
- // 文件名
|
|
|
const filename = '导出核验单EXCEL.xlsx';
|
|
|
- const wb = XLSX.utils.table_to_book(el, { raw: true });
|
|
|
- const wbout = XLSX.write(wb, { bookType: 'xlsx', bookSST: true, type: 'array' });
|
|
|
+
|
|
|
+ // 获取表格数据
|
|
|
+ const ws = XLSX.utils.table_to_sheet(el);
|
|
|
+
|
|
|
+ // 找出需要保留为数字的列(假设'sl'列是数字)
|
|
|
+ const numCols = ['qczl_fp']; // 添加其他需要保留数字的列名
|
|
|
+
|
|
|
+ // 遍历工作表数据,将指定列转换为数字
|
|
|
+ for (const cell in ws) {
|
|
|
+ if (cell[0] === '!') continue; // 跳过特殊属性
|
|
|
+
|
|
|
+ const colName = cell.replace(/[0-9]/g, ''); // 获取列字母
|
|
|
+ const header = ws[colName + '1']; // 获取表头
|
|
|
+
|
|
|
+ if (header && numCols.includes(header.v)) {
|
|
|
+ // 如果是数字列,尝试转换为数字
|
|
|
+ const value = ws[cell].v;
|
|
|
+ if (!isNaN(value) && value !== '') {
|
|
|
+ ws[cell].t = 'n'; // 设置为数字类型
|
|
|
+ ws[cell].v = Number(value); // 转换为数字
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 创建工作簿并导出
|
|
|
+ const wb = XLSX.utils.book_new();
|
|
|
+ XLSX.utils.book_append_sheet(wb, ws, "Sheet1");
|
|
|
+
|
|
|
try {
|
|
|
- FileSaver.saveAs(new Blob([wbout], { type: 'application/octet-stream' }), filename);
|
|
|
+ XLSX.writeFile(wb, filename);
|
|
|
} catch (e) {
|
|
|
console.log(e);
|
|
|
}
|
|
|
- return wbout;
|
|
|
}
|
|
|
-
|
|
|
</script>
|
|
|
|
|
|
<style>
|