Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Sheet Names not Returned Properly with Streaming WorkbookReader #2663

Open
Kkoile opened this issue Jan 18, 2024 · 0 comments 路 May be fixed by #2671
Open

[BUG] Sheet Names not Returned Properly with Streaming WorkbookReader #2663

Kkoile opened this issue Jan 18, 2024 · 0 comments 路 May be fixed by #2671

Comments

@Kkoile
Copy link

Kkoile commented Jan 18, 2024

馃悰 Bug Report

We have an excel which is generated with python openpyxl and adds a sheet named "test":

When trying to read this excel via exceljs streaming api, it doesn't return the correct sheet names, but "Sheet1", "Sheet2".

Steps To Reproduce

  • Download this excel or generate it yourself using the following python code:
from openpyxl import Workbook

wb = Workbook()

test = wb.create_sheet("test")
test["A1"] = "new value"

wb.save("test.xlsx")
  • Execute the following js code
const Excel = require("exceljs");
const fs = require("fs/promises");
const path = require("path");

const run = async () => {
  const file = await fs.open(path.join(__dirname, "test.xlsx"));
  const fileStream = file.createReadStream();
  const workbookReader = new Excel.stream.xlsx.WorkbookReader(fileStream, {});
  for await (const worksheetReader of workbookReader) {
    console.log(worksheetReader.name);
  }
};
run();
  • console.log returns "Sheet1" and "Sheet2" but should return "Sheet1" and "test"

Within workbookRead.model.sheets the sheet name is provided. So I could look it up using

const sheetInfo = workbookReader.model.sheets.find((sheet) => sheet.id == worksheetReader.id);
console.log(sheetInfo.name);

Here the issue is that the behaviour is very nondeterministic and workbookRead.model is not always defined.

When not using the streaming API, the sheets are resolved correctly. So it seems the issue is not within the excel itself:

const workbook = new Excel.Workbook();
await workbook.xlsx.readFile(path.join(__dirname, "test.xlsx"));
workbook.eachSheet((sheet) => {
  console.log(sheet.name);
});

The expected behaviour:

The streaming API should return the correct sheet names using the streaming API.

Possible solution (optional, but very helpful):

n/a

Kkoile pushed a commit to Kkoile/exceljs that referenced this issue Jan 25, 2024
@Kkoile Kkoile linked a pull request Jan 25, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant