模板根据header长度生成
This commit is contained in:
parent
824dc1d702
commit
455710d1eb
|
|
@ -31,7 +31,6 @@ function clearPorts() {
|
||||||
}
|
}
|
||||||
exports.clearPorts = clearPorts;
|
exports.clearPorts = clearPorts;
|
||||||
function getImportation(id) {
|
function getImportation(id) {
|
||||||
console.log(Importations);
|
|
||||||
(0, assert_1.default)(Importations.hasOwnProperty(id), `id为[${id}]的importation不存在`);
|
(0, assert_1.default)(Importations.hasOwnProperty(id), `id为[${id}]的importation不存在`);
|
||||||
return Importations[id];
|
return Importations[id];
|
||||||
}
|
}
|
||||||
|
|
@ -105,6 +104,12 @@ async function getImportationTemplate(params, context) {
|
||||||
throw new Error('未找到对应的模板');
|
throw new Error('未找到对应的模板');
|
||||||
}
|
}
|
||||||
const exportSheet = xlsx_1.utils.json_to_sheet([], { header: headers });
|
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();
|
const exportBook = xlsx_1.utils.book_new();
|
||||||
xlsx_1.utils.book_append_sheet(exportBook, exportSheet);
|
xlsx_1.utils.book_append_sheet(exportBook, exportSheet);
|
||||||
return await (0, xlsx_1.write)(exportBook, { type: 'buffer' });
|
return await (0, xlsx_1.write)(exportBook, { type: 'buffer' });
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,6 @@ export function clearPorts() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function getImportation<ED extends EntityDict, T extends keyof ED>(id: string) {
|
function getImportation<ED extends EntityDict, T extends keyof ED>(id: string) {
|
||||||
console.log(Importations);
|
|
||||||
assert(Importations.hasOwnProperty(id), `id为[${id}]的importation不存在`);
|
assert(Importations.hasOwnProperty(id), `id为[${id}]的importation不存在`);
|
||||||
return Importations[id] as Importation<ED, T, any>;
|
return Importations[id] as Importation<ED, T, any>;
|
||||||
}
|
}
|
||||||
|
|
@ -138,6 +137,14 @@ export async function getImportationTemplate<
|
||||||
throw new Error('未找到对应的模板');
|
throw new Error('未找到对应的模板');
|
||||||
}
|
}
|
||||||
const exportSheet = utils.json_to_sheet([], { header: headers });
|
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();
|
const exportBook = utils.book_new();
|
||||||
utils.book_append_sheet(exportBook, exportSheet);
|
utils.book_append_sheet(exportBook, exportSheet);
|
||||||
return await write(exportBook, { type: 'buffer' });
|
return await write(exportBook, { type: 'buffer' });
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue