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
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:
@@ -222,14 +222,23 @@ async function exportExcel(mode) {
|
||||
row.height = 24
|
||||
}
|
||||
|
||||
function autoCols(ws, minWidth = 10) {
|
||||
ws.columns.forEach(col => {
|
||||
let max = minWidth
|
||||
function autoCols(ws, ingredientCol = -1) {
|
||||
ws.columns.forEach((col, i) => {
|
||||
if (i === 0) {
|
||||
// First column (配方名): fit longest content
|
||||
let max = 8
|
||||
col.eachCell({ includeEmpty: true }, cell => {
|
||||
const len = cell.value ? String(cell.value).length * 1.5 : 0
|
||||
const len = cell.value ? String(cell.value).length * 1.8 : 0
|
||||
if (len > max) max = len
|
||||
})
|
||||
col.width = Math.min(max + 2, 40)
|
||||
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
|
||||
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
|
||||
const buf = await wb.xlsx.writeBuffer()
|
||||
|
||||
Reference in New Issue
Block a user