exceljs / exceljs/exceljs

[BUG] Corrupted Zip error during appending row

Open
#1,547 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
15.5k
Forks
2k
PR merge metrics
No merged PRs in 30d

Description

## 🐛 Bug Report

Below error happens when I am trying to append a new row into existing excel.
I run it in high volume concurrency, basically you can think my script calls web-service to get a return json object, transform json object and insert into excel.
Most time it works fine, but the error occurs after hundreds executions, not always the same time.
![image](https://user-images.githubusercontent.com/46672720/100806937-8022ef80-3485-11eb-9ca0-2c11b0266d1c.png)

Lib version: 4.2.0

## Steps To Reproduce

Below code is responsible for appending jsonData into the last row of excel file.
FYI. I use async-lock package (v1.2.4) to ensure data consistency, other "threads" are unable to read excel until lock is released.

```javascript
async function addRowWithJson(filePath, jsonData) {
await lock
.acquire("excelKey", async function () {
console.log("Acquire lock to write excel");
const workbook = new ExcelJS.Workbook();
await workbook.xlsx.readFile(filePath);

let worksheet = workbook.getWorksheet(sheetName);
worksheet.columns = columnSetting;
const row = worksheet.addRow(jsonData);
row.alignment = { vertical: "bottom", horizontal: "center" };

await workbook.xlsx.writeFile(filePath);
console.log("Row added");
})
.then(function () {
console.log("Release lock");
})
.catch((error) => {
return Promise.reject(error);
});
}
```

I want to understand why it happens, then think about how to fix it. Therefore any thoughts is quite welcomed.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.