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

Adds multiple rows with index #734

Merged
merged 6 commits into from
Apr 27, 2020
Merged

Adds multiple rows with index #734

merged 6 commits into from
Apr 27, 2020

Conversation

trfi
Copy link
Contributor

@trfi trfi commented Mar 21, 2020

Adds multiple rows to the worksheet at the specified index and populates it with values

trfi added 3 commits March 21, 2020 12:35
Adds multiple rows to the worksheet at the specified index and populates it with values
@burnash burnash added this to the 3.5.0 milestone Apr 5, 2020
@burnash
Copy link
Owner

burnash commented Apr 17, 2020

Thank you very much for your contribution. My bad I've missed this PR and added append_rows() from #556 and #694.
However, I think your contribution could be used as insert_rows() method that gspread is currently missing. For that, we would need to change the method name in the PR and the API call.

Let me know if you're interested in changing the PR.

@burnash burnash modified the milestones: 3.5.0, 3.6.0 Apr 17, 2020
@garethsb
Copy link

It would be very nice if the "insertDimension" and the values were put atomically. I think it would be possible by using "updateCells" ?

@burnash
Copy link
Owner

burnash commented Apr 21, 2020

@garethsb-sony very good point. Thank you for the suggestion.

For the record, here's the link to updateCells docs: UpdateCellsRequest

@tr-fi let me know if you need help with reworking the PR.

@garethsb
Copy link

Thanks, @burnash ! (I assume insert_row should be reworked to call the new insert_rows as well, like append_row in master calls append_rows?)

@burnash
Copy link
Owner

burnash commented Apr 21, 2020

@garethsb-sony yes, exactly. I'm also trying to figure out if the scalar versions of these methods are still needed. Maybe it would be a good idea to deprecate the scalar versions and reduce the API surface a bit.

change method name
@trfi
Copy link
Contributor Author

trfi commented Apr 21, 2020

@burnash You right insert_rows is more reasonable. So I changed the method name to insert_rows.

gspread/models.py Outdated Show resolved Hide resolved
fix indentation line wrong
@burnash burnash self-requested a review April 27, 2020 13:02
"range": {
"sheetId": self.id,
"dimension": "ROWS",
"startIndex": index - 1,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like there's a problem with insert indices.

Steps to reproduce:

  1. I have a sheet with consecutive values:

Screenshot 2020-04-27 at 15 00 55

  1. I call
wks.insert_rows([['r1.1','r1.2'],['r2.1', 'r2.2']], index=3)

Where wks is my worksheet.

  1. I get

Screenshot 2020-04-27 at 15 01 20

Where the expected result is 1, 2, r1.1, r2.1, 3, 4, etc in the column A.
It looks like the method overwrites the cell with value "3".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I did not test thoroughly. I fixed it but need you test again

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem, thank you for fast response

Fix index not working exactly
@burnash burnash merged commit 7f473f2 into burnash:master Apr 27, 2020
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.

3 participants