I was wondering if there is a API call for Google Sheets where I can delete all cells in a given sheet and paste/replace with a new data. I have the new data in the form of its own sheet.
thanks!
Update cell values with Google Sheets API
Since you mentioned that you need an API call for this, I think your way to go is to use the batchUpdate method from the Google Sheets API as it is the closest thing to what you are looking for.
With the batchUpdate method you can send a UpdateCellsRequestin order to replace the information from the cells you are looking for. I will leave the official documentation below so that you can check what I just mentioned.
References:
Method: batchUpdate
Reading & Writing Cell Values
UpdateCellsRequest
For a large existing file, it seems most expedient to delete the file and create a new one with Apps Script.
For delete, you can use DriveApp. Look for methods such as .getFileById(). Or, if you prefer to programmatically search for a filename in a folder, look for .getFolderById() and .getFilesByName(). Once you get the file object, you can either use Drive API's .remove() as shown in this answer or use DriveApp's .File.setTrashed. But note the latter moves file to trash bin, not literally remove from drive.
For file creation, you can use Advanced Drive Service. see this answer for exact steps.
As for populating the new sheet, the OP implies that step is already understood. (No particular data format was provided.) So we are done!
Related
After multiple test and research I don't have success in importing the data of this table (div) into a Google slide.
None of the formula I tested actually work included this simple test to extract the first column/line "Name":
=importxml("https://ecosystem.lafrenchtech.com/lists/18872/list?showGrid=false", "//span[#class='table-column-text']")
:(
Anyone could help me ?
Thx by advance.
Answer:
I've tested your function on a test sheet and it returns an empty content.
According to an answer at Google Sheets importXML Returns Empty Value , IMPORTXML can not retrieve data which is being populated by a script and it is a limitation. Unfortunately, I have checked that when Javascript is disabled for the ecosystem.lafrenchtech.com site in Chrome browser, the table never loads. Thus, this confirms that the table is being populated by a script and this is the reason why it returns an empty content.
A possible alternative solution is to check if the ecosystem.lafrenchtech.com offers an API, where you can directly get the data that they show from their table using an API key (if it is available). However, this will require you to use Apps Script to parse the data from their API and then post it on your spreadsheet, which would be quite a tedious for a quite simple process.
Note:
On your post, google-slides was the set tag.
I made a google sheet and i want to make it as a question. I need this all the data in this sheet recorded in a new sheet after people answer it and I want the table empty for next user to answer the question. And where can i get the response?
What I suggest is to make a copy for each person who is going to use it.
When you share your spreadsheet with them you change ending of your URL.
Istead of:
https://docs.google.com/spreadsheets/d/XXXXXXXXXXXXhere is youd document ID XXXXXXXXXXXXX/edit#gid=1535248610
You send them
https://docs.google.com/spreadsheets/d/XXXXXXXXXXXXhere is youd document ID XXXXXXXXXXXXX/copy
This way everyone will fill the different copy of the table and have to later share it with you.
Different option is to use a script that copies content to the new file.
You also can use Google form for this job.
I'm facing an issue within updating of existing spreadsheet on google drive, without using a batch update (right now I'm not sure whether it is even possible)
I already have existing spreadsheet with some data, then I retrieve file from google drive via
Drive drive = new Drive.Builder(TRANSPORT, JSON_FACTORY, credential)
.setApplicationName(APPLICATION_NAME)
.build();
drive.files().list().execute().getItems()
I easily match my file by the name and then I just want to update the spreadsheet in the founded file.
Sheets service = new Sheets.Builder(GoogleNetHttpTransport.newTrustedTransport(), JSON_FACTORY, credential)
.setApplicationName(APPLICATION_NAME)
.build();
Spreadsheet spreadsheet = service.spreadsheets().get(file.getId()).execute().setSheets(new ArrayList<>());
Here I get spreadsheet from file which match the name and then I just want to put there empy sheet (for example).
There is first point, where I'm not sure how to correctly "update" the spreadsheet on drive, because I cannot use
service.spreadsheets().create(spreadsheet).execute();
and I don't want to use batch update, because I already have set the spreadsheet content via setSheet() method.
I think it should be finalized with following:
Permission permission = drive.permissions().get(file.getId(), permissionId).execute().setType("anyone");
drive.permissions().update(
spreadsheet.getSpreadsheetId(),
permissionId,
permission
).execute();
I was checking the google API here:
https://developers.google.com/drive/v2/reference/permissions/update
and here:
https://developers.google.com/sheets/api/guides/batchupdate
but they are using batch update.
What I am curious is why there is setSheets() method, which seems to be easily to use for updates, when I already created my sheets, but it seems that I just cannot simply update spreadsheet in existing file.
What is also interesting that every time I use the drive.perm.update, it creates a new file(with spreadsheet that I wanted to update) which actually doesn't make much sense to me.
So is there any chance to simply update file on drive and just use the spreadsheet method?
This statement by Jay Lee in this related SO post will give a clear insight:
The Google Drive API is meant for generic file / folder interactions. For directly modifying Google Spreadsheet data, the Google Sheets API would be the better choice.
Furthermore, to update Google spreadsheet, you may want to check Reading & Writing Cell Values which describes the basics of using the spreadsheets.values collection. It was mentioned that,
If you need to update formatting or other properties in a sheet, you will need to use the spreadsheets collection, which is described in Updating Spreadsheets.
For more information, please see Batch update operations and examples are shown here.
I have a problem in my reporting, i create every day a google doc tracker where all the stack holders in my department update their work progress in it, so i have plenty of spreadsheets to monitor which is a hassle, here is what im trying to do, I'm trying to create a big google doc tracker where i can have an access over date applied in the normal spreadsheets, all what i need is the spreadsheet's URLs that exist in my google drive to be retrieved in this big tracker, with this i'll be able to drive all the needed data from the normal trackers.
PS: I'm not good with google scripts.
You can use the Drive Service to get a list of files with MIME type "application/vnd.google-apps.spreadsheet" using getFilesByType. This returns a FileIterator, which you can use to individually get each Spreadsheet file. From there, just use getUrl() to find the URL's. The FileIterator link has examples of how to loop through all the matching files.
Currently we're having a request to integrate the Google Form functionality into our system. I'd done some searching on the web, and found that there's no way we can change the post processing of a Google Form unless we do some heavy customization using 3rd party tools.
Thus i have an idea that, when someone fill in the Google Form, he/she will need to fill in a 'user id' in the form. This will be collected as a field in the Google Spreadsheet generated by the form.
In my back end application, i would query the spreadsheet and look for the user id field input by the user. Then i would be able to know whether he/she completed the form or not.
I'm trying to look at the Google Docs API for the spreadsheet and found that there are list-based feed and cell-based feed but i'm not sure which one can achieve what i want to do. Anyone has experience in this can shed a light?
Thank you
Think of a list based feed as being like SQL. You can read rows, insert rows(at the bottom), delete rows and update rows. - you can only store data, not formulas. In contrast, A CELL based feed lets you read and write to cells, any cell, using the cell reference (R1C1 style). CELL FEED give you more control, and includes batch updates.
some sample CELL FEED code is here:
http://code.google.com/p/gdata-java-client/source/browse/trunk/java/sample/spreadsheet/cell/CellDemo.java?r=51
Another option is too use google apps script, this is maybe less work if you just want to extract data. The html service is probably the tool for the job https://developers.google.com/apps-script/html_service - as you can dont need OAuth to do the read.