Node.js 如何在excel4node中打印json数组

Node.js 如何在excel4node中打印json数组,node.js,excel4node,Node.js,Excel4node,我必须打印一个10000行的excel。有任何方法可以使用excel4node?批量打印json数组 e、 例如:Mongodb insertMany操作为此,您可以创建一个以json作为输入的函数,并在函数内部对其进行迭代。 因此,如果你想要的话,你可以将你的操作视为一个单独的操作。我从npm作者那里找到了一个要点。看来已经不可能做到了 例如: const xl = require('excel4node'); // Create workbook and add worksheet con

我必须打印一个10000行的excel。有任何方法可以使用excel4node?批量打印json数组


e、 例如:Mongodb insertMany操作

为此,您可以创建一个以json作为输入的函数,并在函数内部对其进行迭代。
因此,如果你想要的话,你可以将你的操作视为一个单独的操作。

我从npm作者那里找到了一个要点。看来已经不可能做到了

例如:

const xl = require('excel4node');

// Create workbook and add worksheet
const wb = new xl.Workbook();
const ws = wb.addWorksheet('Data', {
  disableRowSpansOptimization: true,
});

// Generate some fake data for testing
const data = [];
const rowCount = 50000;
let row = 1;
while (row <= rowCount) {
  data.push({
    zone_name: `zone_name_${row}`,
    circle_name: `circle_name_${row}`,
    div_town_name: `div_town_name_${row}`,
    tender_name: `tender_name_${row}`,
    tkc_name: `tkc_name_${row}`,
    work_name: `work_name_${row}`,
    material_name: `material_name_${row}`,
    insert_dttm: new Date(),
    app_fname: `app_fname_${row}`,
    ins_fname: `ins_fname_${row}`,
  });
  row += 1;
}

const startRow = 4;
// Add data to worksheet
if (data.length) {
  data.forEach((item, i) => {
    const currentRow = i + startRow;
    const newtarget = 'newtarget';
    const newprogress = 'newprogress';

    ws.cell(currentRow, 1).number(i).style({
      alignment: {
        vertical: ['center'],
        horizontal: ['left']
      },
      font: {
        color: '000000',
        size: 12
      },
      border: {
        bottom: {
          style: 'thin',
          color: '000000'
        },
        right: {
          style: 'thin',
          color: '000000'
        },
        left: {
          style: 'thin',
          color: '000000'
        },
        top: {
          style: 'thin',
          color: '000000'
        }
      }
    });
    ws.cell(currentRow, 2).string(item.zone_name).style({
      alignment: {
        vertical: ['center'],
        horizontal: ['left']
      },
      font: {
        color: '000000',
        size: 12
      },
      border: {
        bottom: {
          style: 'thin',
          color: '000000'
        },
        right: {
          style: 'thin',
          color: '000000'
        },
        left: {
          style: 'thin',
          color: '000000'
        },
        top: {
          style: 'thin',
          color: '000000'
        }
      }
    });
    ws.cell(currentRow, 3).string(item.circle_name).style({
      alignment: {
        vertical: ['center'],
        horizontal: ['left']
      },
      font: {
        color: '000000',
        size: 12
      },
      border: {
        bottom: {
          style: 'thin',
          color: '000000'
        },
        right: {
          style: 'thin',
          color: '000000'
        },
        left: {
          style: 'thin',
          color: '000000'
        },
        top: {
          style: 'thin',
          color: '000000'
        }
      }
    });
    ws.cell(currentRow, 4).string(item.div_town_name).style({
      alignment: {
        vertical: ['center'],
        horizontal: ['left']
      },
      font: {
        color: '000000',
        size: 12
      },
      border: {
        bottom: {
          style: 'thin',
          color: '000000'
        },
        right: {
          style: 'thin',
          color: '000000'
        },
        left: {
          style: 'thin',
          color: '000000'
        },
        top: {
          style: 'thin',
          color: '000000'
        }
      }
    });
    ws.cell(currentRow, 5).string(item.tender_name).style({
      alignment: {
        vertical: ['center'],
        horizontal: ['left']
      },
      font: {
        color: '000000',
        size: 12
      },
      border: {
        bottom: {
          style: 'thin',
          color: '000000'
        },
        right: {
          style: 'thin',
          color: '000000'
        },
        left: {
          style: 'thin',
          color: '000000'
        },
        top: {
          style: 'thin',
          color: '000000'
        }
      }
    });
    ws.cell(currentRow, 6).string(item.tkc_name).style({
      alignment: {
        vertical: ['center'],
        horizontal: ['left']
      },
      font: {
        color: '000000',
        size: 12
      },
      border: {
        bottom: {
          style: 'thin',
          color: '000000'
        },
        right: {
          style: 'thin',
          color: '000000'
        },
        left: {
          style: 'thin',
          color: '000000'
        },
        top: {
          style: 'thin',
          color: '000000'
        }
      }
    });
    ws.cell(currentRow, 7).string(item.work_name).style({
      alignment: {
        vertical: ['center'],
        horizontal: ['left']
      },
      font: {
        color: '000000',
        size: 12
      },
      border: {
        bottom: {
          style: 'thin',
          color: '000000'
        },
        right: {
          style: 'thin',
          color: '000000'
        },
        left: {
          style: 'thin',
          color: '000000'
        },
        top: {
          style: 'thin',
          color: '000000'
        }
      }
    });
    ws.cell(currentRow, 8).string(item.material_name).style({
      alignment: {
        vertical: ['center'],
        horizontal: ['left']
      },
      font: {
        color: '000000',
        size: 12
      },
      border: {
        bottom: {
          style: 'thin',
          color: '000000'
        },
        right: {
          style: 'thin',
          color: '000000'
        },
        left: {
          style: 'thin',
          color: '000000'
        },
        top: {
          style: 'thin',
          color: '000000'
        }
      }
    });
    ws.cell(currentRow, 9).string(newtarget).style({
      alignment: {
        vertical: ['center'],
        horizontal: ['left']
      },
      font: {
        color: '000000',
        size: 12
      },
      border: {
        bottom: {
          style: 'thin',
          color: '000000'
        },
        right: {
          style: 'thin',
          color: '000000'
        },
        left: {
          style: 'thin',
          color: '000000'
        },
        top: {
          style: 'thin',
          color: '000000'
        }
      }
    });
    ws.cell(currentRow, 10).string(newprogress).style({
      alignment: {
        vertical: ['center'],
        horizontal: ['left']
      },
      font: {
        color: '000000',
        size: 12
      },
      border: {
        bottom: {
          style: 'thin',
          color: '000000'
        },
        right: {
          style: 'thin',
          color: '000000'
        },
        left: {
          style: 'thin',
          color: '000000'
        },
        top: {
          style: 'thin',
          color: '000000'
        }
      }
    });
    ws.cell(currentRow, 11).date(item.insert_dttm).style({
      alignment: {
        vertical: ['center'],
        horizontal: ['left']
      },
      font: {
        color: '000000',
        size: 12
      },
      border: {
        bottom: {
          style: 'thin',
          color: '000000'
        },
        right: {
          style: 'thin',
          color: '000000'
        },
        left: {
          style: 'thin',
          color: '000000'
        },
        top: {
          style: 'thin',
          color: '000000'
        }
      }
    });
    ws.cell(currentRow, 12).string(item.app_fname).style({
      alignment: {
        vertical: ['center'],
        horizontal: ['left']
      },
      font: {
        color: '000000',
        size: 12
      },
      border: {
        bottom: {
          style: 'thin',
          color: '000000'
        },
        right: {
          style: 'thin',
          color: '000000'
        },
        left: {
          style: 'thin',
          color: '000000'
        },
        top: {
          style: 'thin',
          color: '000000'
        }
      }
    });
    ws.cell(currentRow, 13).string(item.ins_fname).style({
      alignment: {
        vertical: ['center'],
        horizontal: ['left']
      },
      font: {
        color: '000000',
        size: 12
      },
      border: {
        bottom: {
          style: 'thin',
          color: '000000'
        },
        right: {
          style: 'thin',
          color: '000000'
        },
        left: {
          style: 'thin',
          color: '000000'
        },
        top: {
          style: 'thin',
          color: '000000'
        }
      }
    });
  });
}

// Write workbook once all data has been added to worksheet
wb.write('Overall_Progress_Report.xlsx');

正如您所见,他迭代json数组。

对不起,这不是我真正想要的。我知道我可以迭代数组,但我想知道是否有可能在一个操作中打印所有内容。像mongodb updateMany操作一样。