fix: 空数据时给空表格

This commit is contained in:
TsMask
2023-10-09 19:59:05 +08:00
parent 62410620ed
commit f7a1a78679

View File

@@ -21,8 +21,8 @@ export const xlsxUrl = `${
*/
export async function readLoalXlsx(id: string): Promise<Record<string, any>[]> {
let fileBolb = await (await fetch(`${xlsxUrl}/${id}.xlsx`)).arrayBuffer();
if(!fileBolb.byteLength){
fileBolb = await (await fetch(`${xlsxUrl}/all.xlsx`)).arrayBuffer();
if (!fileBolb.byteLength) {
fileBolb = await (await fetch(`${xlsxUrl}/all.xlsx`)).arrayBuffer();
}
return readSheet(fileBolb, 0);
}
@@ -54,6 +54,9 @@ export async function readSheet(
*
*/
export async function writeSheet(data: any[], sheetName: string) {
if (data.length === 0) {
return new Blob([], { type: 'application/octet-stream' });
}
const workSheet = utils.json_to_sheet(data);
// 设置列宽度,单位厘米
workSheet['!cols'] = Object.keys(data[0]).map(() => {