Exceljs追加行
Posted
技术标签:
【中文标题】Exceljs追加行【英文标题】:Exceljs append row 【发布时间】:2020-12-09 11:43:44 【问题描述】:我编写了这段代码,以便可以将一些信息保存在 excel 文件中,但它会为每个用户运行多次,并且由于某种原因,它不会追加新行,而是删除旧行并写入新行。有人可以帮忙吗?
// A new Excel Work Book
var workbook = new Excel.Workbook();
// Create a sheet
var sheet = workbook.addWorksheet("Sheet1");
// Add rows in the above header
sheet.addRow(
user_id: info.id,
user_tag: username,
followed_by: inform.username,
followers: info.edge_followed_by.count,
followings: info.edge_follow.count,
biography: info.biography,
category: info.business_category_name,
external_url: info.external_url,
external_lynx_url: info.external_url_linkshimmed,
is_verified: info.is_verified,
);
// Save Excel on Hard Disk
workbook.xlsx.writeFile("business_accounts.xlsx").then(function ()
// Success Message
alert("User Saved");
);
【问题讨论】:
【参考方案1】:// A new Excel Work Book
var workbook = new Excel.Workbook();
// Create a sheet
var sheet = workbook.addWorksheet("Sheet1");
for (user of users)
// Add rows in the above header
sheet.addRow(
user_id: info.id,
user_tag: username,
followed_by: inform.username,
followers: info.edge_followed_by.count,
followings: info.edge_follow.count,
biography: info.biography,
category: info.business_category_name,
external_url: info.external_url,
external_lynx_url: info.external_url_linkshimmed,
is_verified: info.is_verified,
);
// Save Excel on Hard Disk
workbook.xlsx.writeFile("business_accounts.xlsx").then(function ()
// Success Message
alert("User Saved");
);
所有用户只需要一个 excel 文件,因此只需要重复 addrow 函数。确保您只创建和编写一次。
【讨论】:
以上是关于Exceljs追加行的主要内容,如果未能解决你的问题,请参考以下文章