From 455710d1ebe438e9b57a5b0e841011e94b414c1a Mon Sep 17 00:00:00 2001 From: wenjiarui Date: Mon, 13 Mar 2023 10:39:01 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A8=A1=E6=9D=BF=E6=A0=B9=E6=8D=AEheader?= =?UTF-8?q?=E9=95=BF=E5=BA=A6=E7=94=9F=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/port.js | 7 ++++++- src/port.ts | 9 ++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/port.js b/lib/port.js index d394769..4ec65cd 100644 --- a/lib/port.js +++ b/lib/port.js @@ -31,7 +31,6 @@ function clearPorts() { } exports.clearPorts = clearPorts; function getImportation(id) { - console.log(Importations); (0, assert_1.default)(Importations.hasOwnProperty(id), `id为[${id}]的importation不存在`); return Importations[id]; } @@ -105,6 +104,12 @@ async function getImportationTemplate(params, context) { throw new Error('未找到对应的模板'); } const exportSheet = xlsx_1.utils.json_to_sheet([], { header: headers }); + const widthList = headers.map((ele) => { + return { + width: ele.length * 2.2, + }; + }); + exportSheet['!cols'] = widthList; const exportBook = xlsx_1.utils.book_new(); xlsx_1.utils.book_append_sheet(exportBook, exportSheet); return await (0, xlsx_1.write)(exportBook, { type: 'buffer' }); diff --git a/src/port.ts b/src/port.ts index 1b2018e..702e0fd 100644 --- a/src/port.ts +++ b/src/port.ts @@ -34,7 +34,6 @@ export function clearPorts() { } function getImportation(id: string) { - console.log(Importations); assert(Importations.hasOwnProperty(id), `id为[${id}]的importation不存在`); return Importations[id] as Importation; } @@ -138,6 +137,14 @@ export async function getImportationTemplate< throw new Error('未找到对应的模板'); } const exportSheet = utils.json_to_sheet([], { header: headers }); + const widthList = headers.map( + (ele: string) => { + return { + width: ele.length * 2.2, + }; + } + ) + exportSheet['!cols'] = widthList; const exportBook = utils.book_new(); utils.book_append_sheet(exportBook, exportSheet); return await write(exportBook, { type: 'buffer' });