|
@@ -3240,27 +3240,51 @@ const GetInfo = async (value) => {
|
|
|
console.log(formData);
|
|
console.log(formData);
|
|
|
}
|
|
}
|
|
|
};
|
|
};
|
|
|
-const exportToExcel2 = () => {
|
|
|
|
|
-
|
|
|
|
|
- const el = document.getElementById("tab");
|
|
|
|
|
- // 文件名
|
|
|
|
|
- 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",
|
|
|
|
|
- });
|
|
|
|
|
- try {
|
|
|
|
|
- FileSaver.saveAs(
|
|
|
|
|
- new Blob([wbout], { type: "application/octet-stream" }),
|
|
|
|
|
- filename
|
|
|
|
|
- );
|
|
|
|
|
- } catch (e) {
|
|
|
|
|
- console.log(e);
|
|
|
|
|
|
|
+
|
|
|
|
|
+ const exportToExcel2 = () => {
|
|
|
|
|
+ const el = document.getElementById("tab");
|
|
|
|
|
+
|
|
|
|
|
+ if (!el) {
|
|
|
|
|
+ console.error('Table element not found!');
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ const filename = '工序大废品.xlsx';
|
|
|
|
|
+ const wb = XLSX.utils.table_to_book(el, { raw: true });
|
|
|
|
|
+ const ws = wb.Sheets[wb.SheetNames[0]]; // 获取第一个工作表
|
|
|
|
|
+
|
|
|
|
|
+// 获取工作表的范围
|
|
|
|
|
+const range = XLSX.utils.decode_range(ws['!ref']);
|
|
|
|
|
+
|
|
|
|
|
+// 遍历每一行(从第二行开始)
|
|
|
|
|
+for (let R = range.s.r + 1; R <= range.e.r + 1; ++R) {
|
|
|
|
|
+ // 定义要处理的列的起始和结束字符
|
|
|
|
|
+ const startCol = 'G'.charCodeAt(0); // G 的 ASCII 码
|
|
|
|
|
+ const endCol = 'Q'.charCodeAt(0); // Q 的 ASCII 码
|
|
|
|
|
+
|
|
|
|
|
+ // 遍历从 G 到 Q 的每一列
|
|
|
|
|
+ for (let colCode = startCol; colCode <= endCol; ++colCode) {
|
|
|
|
|
+ // 将 ASCII 码转换回列字母
|
|
|
|
|
+ const colLetter = String.fromCharCode(colCode);
|
|
|
|
|
+ const cell = ws[`${colLetter}${R}`];
|
|
|
|
|
+
|
|
|
|
|
+ // 检查单元格是否存在且其值是字符串类型
|
|
|
|
|
+ if (cell && typeof cell.v === 'string') {
|
|
|
|
|
+ const num = Number(cell.v);
|
|
|
|
|
+ if (!isNaN(num)) {
|
|
|
|
|
+ // 修改单元格类型为数字,并更新值
|
|
|
|
|
+ cell.t = 'n';
|
|
|
|
|
+ cell.v = num;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
- return wbout;
|
|
|
|
|
-};
|
|
|
|
|
|
|
+}
|
|
|
|
|
+ const wbout = XLSX.write(wb, { bookType: 'xlsx', bookSST: true, type: 'array' });
|
|
|
|
|
+ try {
|
|
|
|
|
+ FileSaver.saveAs(new Blob([wbout], { type: 'application/octet-stream' }), filename);
|
|
|
|
|
+ } catch (e) {
|
|
|
|
|
+ console.error('Error saving file:', e);
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
// 导出excel
|
|
// 导出excel
|
|
|
// function exportExcel() {
|
|
// function exportExcel() {
|
|
|
// Execelport()
|
|
// Execelport()
|