Comments (5)
the related functions we have are
worksheet.append_row
(which calls append_rows([row]))worksheet.append_rows
worksheet.insert_row
(which calls insert_rows([row]))worksheet.insert_rows
worksheet.insert_cols
Does worksheet.insert_cols
fit your needs?
from gspread.
No it does not.
A | B | |
---|---|---|
1 | ||
2 |
If we want to append data to a new column C which does not exist in the spreadsheet, and use insert_cols
, I assume it would be something like this and it will raise error.
It is the same thing when inserting data to a new row 3.
sheet.insert_cols([values], 3)
sheet.insert_rows([values], 3)
APIError: [400]: Invalid requests[0].insertDimension: range.startIndex must be less than the grid size (2) if inheritFromBefore is false.
Widens the worksheet if there are more values than columns.
append_rows
has this behavior where it will automatically add new rows to match values if the target row does not exist and this is what is needed for columns too.
sheet.append_rows([values])
→ Succeed to add values to newly created row 3
from gspread.
This is a nice feature !
I ran some tests and the google API does not behave exactly what we expect it to 😞
This is the sheet I start with:
A | B | |
---|---|---|
1 | ||
2 |
I tries the API endpoint to append values (the exact same one as Worksheet.append_rows()
I got the following result:
A | B | |
---|---|---|
1 | X | |
2 | Y |
it did take the list of values as a column, and append the value on a column (meaning first value in the list goes to the top of the column and the rest follow bellow on the same column).
Though: the API appends the value on the first empty column it finds.... Fine, be it, may be it appends column from the left-most cell with values.
So I ran the exact same code again and got:
A | B | |
---|---|---|
1 | X | |
2 | Y | |
3 | X | |
4 | Y |
🤦 alright, in fact the API appends the values bellow any existing values, creating the necessary rows if needed, but always bellow on the next row anyway...
I managed to get the following result:
A | B | C | |
---|---|---|---|
1 | X | X | |
2 | Y | Y | |
3 | X | ||
4 | Y |
but I had to set the column myself in the requested range, which is the opposite of what we want. The idea of Worksheet.append_rows()
is: I don't know the size of my spreadsheet, I just want to append values below the last row and I want new rows to be created if necessary.
If this feature is still useful to then we can plan it to the next minor release. just let us know 🙃
from gspread.
The idea of Worksheet.append_rows() is: I don't know the size of my spreadsheet, I just want to append values below the last row and I want new rows to be created if necessary.
If the append_cols()
could be the equivalent to this behavior it would be appreciated:
I just want to append values right to the last column (with values) and I want new columns to be created if necessary
If we need to specify the range ourself, I think we can just leave it until we have a better solution.
from gspread.
The idea of Worksheet.append_rows() is: I don't know the size of my spreadsheet, I just want to append values below the last row and I want new rows to be created if necessary.
If the
append_cols()
could be the equivalent to this behavior it would be appreciated: I just want to append values right to the last column (with values) and I want new columns to be created if necessary
I understand, that's what I tried to do and it does not work this way 😞
If we need to specify the range ourself, I think we can just leave it until we have a better solution.
I understand, then we'll leave it like this for now. I checked again and the google sheet API documentation is clear:
values are appended after the last row of the table
closing this issue for now, until we find a better way.
from gspread.
Related Issues (20)
- improve documentation HOT 2
- cell.expand('table') feature requests HOT 7
- add `value_render_option` to examples (automatic conversion of currency) HOT 6
- Update conda forge package HOT 2
- A way to add DataValidation HOT 6
- Missing py.typed marker HOT 1
- AttributeError: 'HTTPClient' object has no attribute 'import_csv' HOT 3
- Unable to read public readonly spreadsheet HOT 4
- Add missing types HOT 2
- Disambiguating and filling in headers similar to Pandas HOT 8
- worksheet.add_protected_range() - impossible to create the `warning_only=True` range HOT 2
- ADC Authentication HOT 2
- HTTPSConnectionPool(host='oauth2.googleapis.com', port=443): Max retries exceeded with url: /token (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate (_ssl.c:1000)'))) HOT 2
- Questions about Copilot + Open Source Software Hierarchy HOT 1
- gspread depends on google-auth>2.4.0 but only specifies google-auth>=1.12.0 HOT 7
- Client.copy(..., copy_permissions=True) breaks when permission type is domain HOT 1
- Remove StrEnum dependency HOT 6
- Feature request. Batch Merge in worksheet class HOT 2
- lint failure
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gspread.