diff --git a/frontend/src/views/KitExport.vue b/frontend/src/views/KitExport.vue index ff1a8e9..e8e4a41 100644 --- a/frontend/src/views/KitExport.vue +++ b/frontend/src/views/KitExport.vue @@ -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()