-
Notifications
You must be signed in to change notification settings - Fork 952
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
Feature request. Batch Merge in worksheet class #1473
Comments
Hello, thank you for your feature request, this is something we can do. I would like to clarify a few details:
In order to do batch merge request here is a sample code you can use, I believe this is what you already use, but just in case I put the example here. file = gspread.open("myFile")
sheet = gspread.sheet1
request = {
"requests": [
{
"mergeCells": {
"range": gspread.utils.a1_range_to_grid_range("A1:B1", sheet.id),
"mergeType": gspread.utils.MergeType.merge_rows,
}
},
{
"mergeCells": {
"range": gspread.utils.a1_range_to_grid_range("A2:B2", sheet.id),
"mergeType": gspread.utils.MergeType.merge_rows,
}
}
]
}
res = client.http_client.batch_update(file.id, request) When we get a chance we'll add this feature. for the new feature I propose we make this way: spreadsheet.batch_merge(merges: Dict[str, MergeType]) The above type is to be adjusted after some test. |
Thank you so much @lavigne958 for your speedy reply on the issue. Yes that is indeed what i currently do and it does work perfectly. I should say the reason i requested the feature is more from an abstraction side. One of those nice to haves. It is definitely a feature that is low priority. Thanks again! |
@lavigne958 wouldn't it be better to have this method on the |
yes, it would be better to have it at the worksheet level. the pseudo code should like this:
unless I miss something ? |
Created a `batch_merge` function [Issue #1473]
Is your feature request related to a problem? Please describe.
I am using gspread to create quite a large spreadsheet in a particular format. One of the things that is very present in the worksheet are merged cells. The
batch_update
,batch_format
, andbatch_get
have been invaluable to me. However, there is no way from the worksheet side (that i can see) to do a batch merge.I understand that logically merging cells should be done before you insert data. One thing that i find myself doing is having a long list of
merge_cells
at the beginning of my script, which sets up all the merges. However, each makes an API request.Describe the solution you'd like
I would like a
batch_merge
method defined in theWorksheet class
that takes in a list of ranges and uses thebatch_update
method of the Google Sheets API, resulting in only 1 API request. It would most likely need to append multiplemergeCells
to a request body.Describe alternatives you've considered
Currently one of the ways i get around it by making the request myself and then using the
Speadsheet.batch_update
method. However, it would be better if i could do it through some sort of abstraction and keep everything in theWorksheet
classAdditional context
N/A
I am more than happy to attempt to write the method on my own and create a pull request. I understand it is a bit of a niche issue
The text was updated successfully, but these errors were encountered: