fix: 导出列宽 — 配方名自适应,其他列统一窄宽度,成分列35
Some checks failed
PR Preview / teardown-preview (pull_request) Has been skipped
Test / unit-test (push) Failing after 5s
Test / e2e-test (push) Has been skipped
Test / build-check (push) Successful in 4s
PR Preview / test (pull_request) Failing after 6s
PR Preview / deploy-preview (pull_request) Has been skipped

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-14 12:30:06 +00:00
parent b21e798db2
commit 0e3bbf3ba7

View File

@@ -222,14 +222,23 @@ async function exportExcel(mode) {
row.height = 24 row.height = 24
} }
function autoCols(ws, minWidth = 10) { function autoCols(ws, ingredientCol = -1) {
ws.columns.forEach(col => { ws.columns.forEach((col, i) => {
let max = minWidth if (i === 0) {
col.eachCell({ includeEmpty: true }, cell => { // First column (配方名): fit longest content
const len = cell.value ? String(cell.value).length * 1.5 : 0 let max = 8
if (len > max) max = len col.eachCell({ includeEmpty: true }, cell => {
}) const len = cell.value ? String(cell.value).length * 1.8 : 0
col.width = Math.min(max + 2, 40) if (len > max) max = len
})
col.width = Math.min(max + 2, 30)
} else if (i === ingredientCol) {
// Ingredient column: wider
col.width = 35
} else {
// All other columns: uniform narrow width
col.width = 10
}
}) })
} }
@@ -288,7 +297,7 @@ async function exportExcel(mode) {
} }
} }
autoCols(ws) autoCols(ws, mode === 'full' ? 2 : -1)
// Style cost columns // Style cost columns
ws.eachRow((row, rowNum) => { ws.eachRow((row, rowNum) => {
@@ -335,7 +344,9 @@ async function exportExcel(mode) {
}) })
} }
autoCols(csWs) // Cross sheet: ingredient is last column in full mode
const csIngCol = mode === 'full' ? csHeaders.length - 1 : -1
autoCols(csWs, csIngCol)
// Download // Download
const buf = await wb.xlsx.writeBuffer() const buf = await wb.xlsx.writeBuffer()