Skip to content

[BUG] addRows is not defined when using Streaming I/O. #1277

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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
shusson opened this issue May 15, 2020 · 5 comments
Open

[BUG] addRows is not defined when using Streaming I/O. #1277

shusson opened this issue May 15, 2020 · 5 comments
Labels

Comments

@shusson
Copy link

shusson commented May 15, 2020

🐛 Bug Report

addRows is defined in the type declaration but it does not exist at runtime for Excel.stream.xlsx.WorkbookWriter.

Related to #86 and #569

Lib version: 3.9.0

const workbook = new Excel.stream.xlsx.WorkbookWriter(...);
const worksheet = workbook.addWorksheet("foo");
worksheet.addRows(...); // TypeError: worksheet.addRows is not a function

Looking at the source, addRows looks like it is not implemented for the streaming version of the WorksheetWriter.

A bit of background I would like to add a large batch of rows and commit the batch instead of having to commit each row.

@Alanscut
Copy link
Member

@shusson You can try the following code, I will create a pull request as soon as possible, Of course, we are also very happy to accept your contribution 😄.

(async () => {
  var options = {
    filename: './ownerTest/demoTest/read/issue_1277.xlsx',
    useStyles: true,
    useSharedStrings: true
  }
  var wb = new Excel.stream.xlsx.WorkbookWriter(options);
  var ws = wb.addWorksheet('bort');
  var rows = [
    [5,'Bob',new Date()],
    [6,'Bo2b',new Date()]
  ];
  rows.forEach((row) => {
    ws.addRow(row)
  })
  wb.commit();
})()

@shusson
Copy link
Author

shusson commented May 15, 2020

thanks @Alanscut, but as I understand it committing the workbook will lock the worksheet. i.e I won't be able to add any more rows.

I'll look at opening a PR.

After some investigation it looks like there isn't any performance benefit between committing all the rows together vs committing each row (using WorksheetWriter._stream.write). So for now I'll continue using addRow(...).commit(...). But it would be nice to update the typescript definitions to exclude addRows from the stream worksheet class.

@Alanscut Alanscut added the bug label May 21, 2020
@avnigenc
Copy link

Any progress here? 😿

@yujintang
Copy link

addRows(value, style = 'n') {
const rows = [];
value.forEach(row => {
rows.push(this.addRow(row, style));
});
return rows;
}

@DhyanTD
Copy link

DhyanTD commented Apr 29, 2025

guys we need this feature, please implement 'addRows'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants