user12094588
user12094588

Reputation: 321

How to add multiple records from a loop in Excel?

Need to add multiple records from a loop in Excel. According to the given parameters, it adds to the first column and to the first row. What needs to be replaced by worksheet.cell(1, 1) to add entries to the first column and to all subsequent rows?

for (var i = 0; i < users.length; i++) {
    worksheet.cell(1, 1).string(users[i].NAME).style(style);
}

Upvotes: 0

Views: 941

Answers (1)

Terry Lennox
Terry Lennox

Reputation: 30725

This should do what you want, it will add each user to a new row (in column 1):

for (var i = 0; i < users.length; i++) {
    worksheet.cell(i + 1, 1).string(users[i].NAME).style(style);
}

You can also use a forEach loop if you prefer:

users.forEach((user, index) => worksheet.cell(index + 1, 1).string(user.NAME).style(style));

Upvotes: 0

Related Questions