gpt4 book ai didi

node.js - 如何使用 excel4node 在 excel 表中写入数组

转载 作者:搜寻专家 更新时间:2023-11-01 00:04:07 25 4
gpt4 key购买 nike

我正在使用 Excel4node 包创建一个 excel 文件。 通过使用此代码

// Require library
var excel = require('excel4node');

// Create a new instance of a Workbook class
var workbook = new excel.Workbook();

// Add Worksheets to the workbook
var worksheet = workbook.addWorksheet('Sheet 1');
var worksheet2 = workbook.addWorksheet('Sheet 2');

// Create a reusable style
var style = workbook.createStyle({
font: {
color: '#FF0800',
size: 12
},
numberFormat: '$#,##0.00; ($#,##0.00); -'
});

// Set value of cell A1 to 100 as a number type styled with paramaters of style
worksheet.cell(1,1).number(100).style(style);

// Set value of cell B1 to 300 as a number type styled with paramaters of style
worksheet.cell(1,2).number(200).style(style);

// Set value of cell C1 to a formula styled with paramaters of style
worksheet.cell(1,3).formula('A1 + B1').style(style);

// Set value of cell A2 to 'string' styled with paramaters of style
worksheet.cell(2,1).string('string').style(style);

// Set value of cell A3 to true as a boolean type styled with paramaters of style but with an adjustment to the font size.
worksheet.cell(3,1).bool(true).style(style).style({font: {size: 14}});

workbook.write('Excel.xlsx');

通过使用此代码创建一个 Excel 工作表,现在我想要的是。我想在 excel 表中写入数组。

worksheet.getCell('A1').value = 's.no';

使用代码。它正在将数据写入工作表,但它是逐个单元格地写入数据。在excel表格中写数组需要很多时间

    data=[{s.no:1,Name:'xxx',Age:'22'},
{s.no:2,Name:'yyy',Age:'12'},
{s.no:3,Name:'zzz',Age:'32'}]

我想把数组写到excel表中。

 workbook.write('Excel.xlsx',data);

我是这样给出的,但这也不起作用。谁能解决这个问题。

最佳答案

为什么不用

sheet.cell(row , col ).string(`your value`).style(`your style`);

关于node.js - 如何使用 excel4node 在 excel 表中写入数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51587669/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com