-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
function duplicateRows added #1078
Conversation
@cbeltrangomez84 something went wrong during testing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you could, please add at least one test :)
# Conflicts: # lib/doc/worksheet.js
Sorry @Siemienik I don´t know how to do it. 😳 EDIT: I tried to do it after the above comment, Please tell me it is fixed and if the test is OK, it important for my process as developer. |
@cbeltrangomez84 ok, each important thinks has been done:), If I ask You, please write some documentation to README how to use this function :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool feature - a few suggestions though...
@@ -344,6 +344,49 @@ class Worksheet { | |||
}); | |||
} | |||
|
|||
duplicateRow(start, count) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be useful to add an optional argument "insert" = false that will control whether existing rows below the start row are shifted down or not
@@ -344,6 +344,49 @@ class Worksheet { | |||
}); | |||
} | |||
|
|||
duplicateRow(start, count) { | |||
// I want to add after the start row | |||
start++; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For clarity - it's probably better to leave the start arg as 'immutable' and assign nKeep below to (start + 1).
Here also we could add a const rStart = this._rows[start - 1] to reference the start row as this will not change
const nKeep = start; | ||
const nEnd = this._rows.length; | ||
let i; | ||
let rSrc; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a style issue - I tend to declare vars only where they are needed - e.g. for (let i = ... ), const rSrc = this._rows[ ... ]
Block scoping allows multiple uses of these names
let i; | ||
let rSrc; | ||
|
||
// insert new cells |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thinking out loud here - this for loop is a duplication of code already implemented in worksheet.spliceRows()
Perhaps a better strategy would be to prepare an array of insertion values and let spliceRows() do the donkey work...
const values = this._rows[start - 1].values;
const inserts = new Array(count - 1).fill(values);
const deleteCount = insert ? 0 : count - 1;
this.spliceRows(start + 1, deleteCount, ...inserts);
// copy styles from start row to cloned rows
...
Thanks @guyonroche and @Siemienik I made another pull request with the changes and README (plus another test) |
I added a function to duplicate rows with style and values in a worksheet. It still needs to be improve since formulas are not copied and it does not support merged cells, this function was created to support issue #839