fix: 空数据时给空表格
This commit is contained in:
@@ -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(() => {
|
||||
|
||||
Reference in New Issue
Block a user