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

function duplicateRows added #1078

Merged
merged 15 commits into from
Jan 21, 2020
Merged

Conversation

cbeltrangomez84
Copy link
Contributor

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

@Siemienik
Copy link
Member

@cbeltrangomez84 something went wrong during testing

Copy link
Member

@Siemienik Siemienik left a 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 :)

@cbeltrangomez84
Copy link
Contributor Author

cbeltrangomez84 commented Jan 20, 2020

Sorry @Siemienik I don´t know how to do it. 😳
I sent you an email.

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.

@Siemienik Siemienik merged commit 2eddc05 into exceljs:master Jan 21, 2020
@Siemienik
Copy link
Member

@cbeltrangomez84 ok, each important thinks has been done:),

If I ask You, please write some documentation to README how to use this function :)

Copy link
Collaborator

@guyonroche guyonroche left a 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) {
Copy link
Collaborator

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++;
Copy link
Collaborator

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;
Copy link
Collaborator

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
Copy link
Collaborator

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
...

@cbeltrangomez84
Copy link
Contributor Author

Thanks @guyonroche and @Siemienik

I made another pull request with the changes and README (plus another test)

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 this pull request may close these issues.

4 participants