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

Already on GitHub? Sign in to your account

Duplicate/Copy a sheet into the same workbook? #893

Closed
perfeliclemente opened this issue Nov 20, 2017 · 3 comments
Closed

Duplicate/Copy a sheet into the same workbook? #893

perfeliclemente opened this issue Nov 20, 2017 · 3 comments

Comments

@perfeliclemente
Copy link

Is there a way to duplicate a worksheet in a workbook? Thanks!

@reviewher
Copy link
Contributor

It's POJO (plain old JS objects) down to the core, so you can duplicate the worksheet by roundtripping through JSON:

/* Assuming:
- `wb` is the original workbook
- `name` is the name of the sheet you want to duplicate
- `new_name` is the new name
*/
var ws = wb.Sheets[sname]; // get original worksheet
var new_ws = JSON.parse(JSON.stringify(ws)); // make a copy of the object
XLSX.utils.book_append_sheet(wb, new_ws, new_name); // append the worksheet

@perfeliclemente
Copy link
Author

Thanks!
But how can I also copy the styles from the sheet? I see that only values are copied, but what about the style?

@atljoseph
Copy link

Nobody responded?

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

No branches or pull requests

3 participants