IMPORTDATA function Google Sheets - google-sheets

Does the IMPORTDATA function refresh the data automatically in GSheets?

yes, the IMPORTDATA function refresh the data automatically in GSheets.
it happens every hour.

Related

Google drive sheets importrange

I am looking for a way to import the data from one google drive sheet to another using ImportRange formula. However, I want the data to be synced once per day at a certain time instead of automatically updating as the formulas seems to do. Any help would really be appreciated
Formula used:
={IMPORTRANGE(B2,"sheet1!$A$1");IMPORTRANGE(B3,"sheet1!$A$1");IMPORTRANGE(B4,"sheet1!$A$1"); IMPORTRANGE(B5,"sheet1!$A$1");
IMPORTRANGE(B6,"sheet1!$A$1")
}
You can create a Script (Google Apps Script) that copies the data automatically with Time-driven Triggers (https://developers.google.com/apps-script/guides/triggers).
function copyData() {
// Gets data
var data = SpreadsheetApp.openById("ID1").getSheetByName("SheetName").getRange("A1:B2").getValues();
// Copies data
SpreadsheetApp.openById("ID2").getSheetByName("SheetName").getRange("A1:B2").setValues(data);
}

Google Sheets IMPORTRANGE and QUERY not refreshing

I have been using IMPORTRANGE and QUERY extensively to connect all of my spreadsheets for a while now. But recently noticed that IMPORTRANGE and QUERY will not return proper data unless the source Sheet is open. Also, the data used to automatically update (every 30 min or so, whatever the default refresh rate is) in the background for IMPORTRANGE, but now it will only update if I manually open the Sheet and it will display "Loading...." before returning the data.
Is anybody else having issues with these two functions?
This answer explains the issue you encountered.
In summary:
It doesn't update when the sheet isn't opened.
Recalculation only happens when sheet is opened.
Functions that pull data from outside the spreadsheet recalculate at the following times:
ImportRange: 30 minutes
ImportHtml, ImportFeed, ImportData, ImportXml: 1 hour
GoogleFinance: may be delayed up to 20 minutes
Alternative solution:
You can use time driven triggers and update those values every N minutes/hours instead BUT you will have to create a script for that.
Everytime you trigger, you'd have to use setFormula on every cell you used your importrange and query.
References:
setFormula
Choose how often formulas calculate
Time Driven Triggers

How to read last updated rows in Google Spreadsheets API v4

I'm currently using the Google Spreadsheets API V4 to read a spreadsheet. It works fine, I read and write through it and the changes are immediately reflected in the Google spreadsheet. However, I want changes I make through the web browser to be reflected in my app as well. I can't see any events in the API, and I can't find any way to do it in Google either.
The spreadsheet is relatively large (1500+ rows), so I can't constantly check every single cell for a change.
You can set up an onEdit trigger that will log the edit date and other details in another sheet inside the same spreadsheet.
function onEdit(e){
var range = e.range;
range.setNote('Last modified: ' + new Date());
}

Automatic data record in Google Sheets

I receive the data on the P/E multiple in Google Sheets via GOOGLEFINANCE in the following manner:
=GOOGLEFINANCE("GOOGL","pe")
How to write script in Google Sheets that would record the P/E values (or better the values of a particular cell) every day as at, say, 21:00?
Use Google Apps Script.
You want to write a function that uses the Spreadsheet API to get the value of a given Range in a given Sheet, and then append that value in a new row on a different sheet.
You also want to set up a time-based trigger to execute that function.
As an example, for a bound script with only one worksheet:
function copyA1toA2onSameSheet() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
sheet.getRange("A2").setValue(
sheet.getRange("A1").getValue()
);
}
Note that getActiveSheet will always return the first sheet from a time-based trigger, as there is no UI instance. If you need a different sheet, consider getSheetByName, or using getSheets().

Any way to cache Importrange and make it update only once a week?

I currently use =ImportRange to bring in some data from a public sheet I do not own.
However, it is a lot of data and importrange tries to refresh the data on every page access, and doesn't cache it locally.
Is there a script I can run instead to get the data via importrange, then hard code it into my own sheet and only update it once a week?
You can use the Google Sheets add-on called sheetgo, to automatically update your reference from another sheet. You can use 30 updates for free every month or pay for more updates
But I found this to be effective.
function refreshSheet(){
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheet_name);
//Your operations on the sheet
Utilities.sleep(1000);
}
while(true){
Utilities.sleep(604800000);
refreshSheet();}

Resources