I want to append a row of cells to a google sheet and also attach some developer metadata to that row.
In the Google Sheets v4 API, I know you can use batchUpdate to append a row with the appendCells request, and you can add developer metadata using the createDeveloperMetadata request.
My issue is that I wanna set some developer metadata to specifically the newly appended cells atomically. There's not really a way to specifically ensure the range of the newly added row in createDeveloperMetadata, and if I use two different requests, someone else may insert a row between those requests which could shift all the rows, causing the appended cell's range to be pointing to an incorrect row.
Is there a way to attach developer metadata to a newly added cell atomically?
Answer:
There is not currently way of ensuring that the sheet structure hasn't changed between requests.
More Information:
Your The best option, I think, is to make two sequential requests in the same batch. Though this isn't foolproof, in very unlucky circumstances. Even inserting the row directly using an UpdateCellsRequest isn't foolproof either, as simply knowing which row you inserted the data doesn't exclude the possibility that someone else may insert/delete a row before it between the two requests.
Feature Request:
You can however let Google know that this is a feature that is important for the Sheets API and that you would like to request they implement it. Google's Issue Tracker is a place for developers to report issues and make feature requests for their development services.
The page to file a Feature Request for the Google Sheets API is here.
References:
Requests - UpdateCellsRequest | Sheets API | Google Developers
Requests - AppendCellsRequest | Sheets API | Google Developers
The solution I figured out was essentially:
Fetch the dimensions of the sheet
Perform a batch update with insertDimension, updateCells, and createDeveloperMetadata all performed for the same sheet dimension index at the end of the sheet
This basically ensures that the dimension index will point to the same row for all 3 operations in the batch update, and if the index points out of bounds, all 3 operations will fail
Related
I have a Google Sheet that I'm using as a database for a an app I am building in AppSmith. Really just an interface for people to work with the sheet in a controlled manner.
I'm using the Google Sheet because I'm familiar with layering formulas to make it work the way I want it to work. I have a number of columns that start with an ARRAYFORMULA that gives the name of the column in row 1, blank in blank rows that should be blank, and some programmed information in other rows.
This works great as long as I am working from the spreadsheet or reading/adding rows from the app.
However, when I try to edit the row from the app, the API update will take the "50" that it sees in the column and actually put "50" in the cell, breaking the arrayformula.
Is there any way to prevent API calls from actually editing that column? Or to automatically clear the cell and let the arrayformula expand again?
I found a temporary workaround to push "" for the column(s) I know are arrays, but it seems vulnerable to complications if I add other array columns later, or want to make another form in the app that also updates the sheet.
As a "rule of thumb", avoid having formulas on sheets being used as "databases" (top row used for field names, 2nd row and below used for data). If you really need to use formulas in the spreadsheet instead of doing the calculations on the "APP", add them on a "mirror" sheet.
This is a common recommendation when using ARRAYFORMULAS to do calculations with data comming from Google Forms.
If you think that creating a "mirror" sheet might cause more problems than benefits, if your "APP" is able to limit the number of columns being edited, put the formulas to the right of the last column linked to the app.
Related
Make Google Spreadsheet Formula Repeat Infinitely
So, right now I'm working on adding data to my spreadsheet using google form. I would like to add my second google form response below my first google form response automatically by adding row automatically (im doing this process in another sheet using importrange), even in my first google response has some data on it. The content of these two google form remain the same so i would like to see it in 1 sheet.
The reason why i want to do this is to minimize to create another spreadsheet to collect all the data. When im doing this i always get an error message "#REF!" because i know google form using array to add response.
What i want is like this
Can you guys please help me with it?
Here is my folder.
Thankyou
You should use the below formula which essentially merges the two different ranges from the two different sheets:
={'Question 1'!A1:B11 ; 'Question 2'!A1:B8}
I have a main sheet in witch I copy it and create different versions, kind of like simulating different results.
But every time I want to change something in the main sheet, I have to go in all the other sheets I created and changed.
I don't know if it is possible, but the best way for me would be to create a formula like this:
copyFormula(Sheet1!V2) -> And bringed the exactly same result as if I had gone to Sheet1 copied V2 and pasted it this cell.
I tried to create this formula but failed consistently.
Thanks!!
What you need to do is to manipulate the properties of the sheets.
Here is a reference where you can create those actions.
The Sheets API allows you to create sheets, delete sheets, and control
their properties. The examples on this page illustrate how some common
sheet operations can be achieved with the API.
In these examples, the placeholders spreadsheetId and sheetId are
used to indicate where you would provide those IDs. The spreadsheet
ID can be discovered from the spreadsheet URL; the sheet ID can be
obtained from the spreadsheet.get method.
You can refer to this documentation on how you can read the formula you are needing in the entire sheets.
The Sheets API allows you to read values from cells, ranges, sets of
ranges and entire sheets. The examples on this page illustrate how
some common read operations can be achieved with the
spreadsheets.values collection of this API. You can also read
cell values using the spreadsheets.get method, but in most cases
using spreadsheets.values.get or
spreadsheets.values.batchGet is easier to use.
The documentation says:
"The Sheets API v4 does provide an AppendCells request that can be used with the spreadsheets.batchUpdate method to append a row of data
to a sheet (and simultaneously update the cell properties and
formatting, if desired). However, it is usually easier to simply
determine the A1 notation of the row you wish to add, and then issue a
spreadsheets.values.update request to overwrite that row."
How do you determine the A1 notation of the row you wish to add and/or how does the AppendCells request get made? I'm using php.
That is, I have information in column B, and I'd like a datestamp in column C noting when column B was filled out. I see a bunch of onEdit scripts, but I'd like it to be retroactive--those cells have already been filled out. Is that possible? Does Google Spreadsheets store that information and is it accessible?
Unfortunately, I don't believe it is. As you mention, there are ways to get the timestamp going forward, but the information as to when a cell was filled out is not retroactively available.
The API doucmentation provides an updated field on List and Cells feeds, but that is a sheet-level property. The returned cell data does not contain any other information regarding the date, so the (unfortunate) answer is that you will likely only be able to get that level of information going forward.