fix: 空数据时给空表格
This commit is contained in:
@@ -21,7 +21,7 @@ export const xlsxUrl = `${
|
|||||||
*/
|
*/
|
||||||
export async function readLoalXlsx(id: string): Promise<Record<string, any>[]> {
|
export async function readLoalXlsx(id: string): Promise<Record<string, any>[]> {
|
||||||
let fileBolb = await (await fetch(`${xlsxUrl}/${id}.xlsx`)).arrayBuffer();
|
let fileBolb = await (await fetch(`${xlsxUrl}/${id}.xlsx`)).arrayBuffer();
|
||||||
if(!fileBolb.byteLength){
|
if (!fileBolb.byteLength) {
|
||||||
fileBolb = await (await fetch(`${xlsxUrl}/all.xlsx`)).arrayBuffer();
|
fileBolb = await (await fetch(`${xlsxUrl}/all.xlsx`)).arrayBuffer();
|
||||||
}
|
}
|
||||||
return readSheet(fileBolb, 0);
|
return readSheet(fileBolb, 0);
|
||||||
@@ -54,6 +54,9 @@ export async function readSheet(
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
export async function writeSheet(data: any[], sheetName: string) {
|
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);
|
const workSheet = utils.json_to_sheet(data);
|
||||||
// 设置列宽度,单位厘米
|
// 设置列宽度,单位厘米
|
||||||
workSheet['!cols'] = Object.keys(data[0]).map(() => {
|
workSheet['!cols'] = Object.keys(data[0]).map(() => {
|
||||||
|
|||||||
Reference in New Issue
Block a user