The error message suggests that the function "auto_width" is not available in the "utils" module from the "xlsx" library. \n\nTo modify the column width to fit the content automatically, you can try using the "xlsx-populate" library instead. Here's an example of how you can modify your code:\n\n1. Install the "xlsx-populate" library:\n\nnpm install xlsx-populate\n\n\n2. Import the necessary modules:\njavascript\nimport { writeFile } from 'xlsx-populate';\n\n\n3. Modify the code to adjust the column width:\njavascript\nconst isExcelChange = () => {\n const workbook = new Workbook();\n const worksheet = workbook.addSheet('Sheet 1');\n const table = document.querySelector('#tableData');\n\n // Convert HTML table to worksheet\n XlsxPopulate.fromBlankAsync()\n .then(workbook => {\n const worksheet = workbook.sheet(0);\n const table = document.querySelector('#tableData');\n XlsxPopulate.utils.tableToSheet(table, worksheet);\n\n // Adjust column width\n worksheet.usedRange().columns().forEach(column => {\n column.width(XlsxPopulate.utils.autoWidth(column));\n });\n\n // Save the workbook as Excel file\n if (state.queryForm.type == 2) {\n return workbook.toFileAsync(`各企业流量(日均值)统计${new Date().getTime()}.xlsx`);\n } else {\n return workbook.toFileAsync(`压差分布情况统计${new Date().getTime()}.xlsx`);\n }\n })\n .catch(error => {\n console.error(error);\n });\n}\n\n\nMake sure to replace "#tableData" with the actual ID or selector of your table element.

xlsx 库中自动调整列宽 - 使用 xlsx-populate 解决

原文地址: https://www.cveoy.top/t/topic/pWDm 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录