feat: 套装方案对比与导出功能 #32

Merged
hera merged 37 commits from feat/kit-comparison-export into main 2026-04-14 13:32:34 +00:00
Showing only changes of commit 0e3bbf3ba7 - Show all commits

View File

@@ -222,14 +222,23 @@ async function exportExcel(mode) {
row.height = 24
}
function autoCols(ws, minWidth = 10) {
ws.columns.forEach(col => {
let max = minWidth
col.eachCell({ includeEmpty: true }, cell => {
const len = cell.value ? String(cell.value).length * 1.5 : 0
if (len > max) max = len
})
col.width = Math.min(max + 2, 40)
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.8 : 0
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
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()