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);
}
Related
I need to pull data from a Google Sheet into BigQuery. So far I have created a Table in BQ using the CSV option and all of the data imported fine. But now I need to automatically update the BQ table with the data in the Google Sheet's tab. Can anyone point me in the right direction? Thanks in advance.
With BigQuery you can directly query your data from the Google Sheet by creating an external table from the console.
Given your data is properly formatted, you just have to "create table", from "Drive", provide your Google Sheet uri, fill-in some additional settings and that's it !
Any changes in the spreadsheet will be immediately accessible in BigQuery as well.
Documentation for reference.
I looked at BQ when they released and quickly dismissed it as it is free for a short period and then we have to pay. I have my own domain/website and it comes with MySQL, FTP, and so much more.
Anyway, I have many projects that go the opposite direction, pull the data down from the SQL DB to sheets, but which direction does not really matter.
Google sheets has Triggers, I have triggers set to launch at certain times, usually every day, you get to set up the trigger to fire off a function you specify.
https://developers.google.com/apps-script/reference/script/clock-trigger-builder
You can also set triggers via scripts
/**
* Creates time-driven triggers
*
* https://developers.google.com/apps-script/reference/script/clock-trigger-builder
*/
function createTimeDrivenTriggers() {
// Trigger every day at 04:00AM CT.
ScriptApp.newTrigger('csvDaily')
.timeBased()
.everyDays(1)
.atHour(4)
.create();
}
Context: I need to develop a Google Sheet to manage yearly cost and revenues from the Charity where I volunteer. This file will be updated from volunteers, so I need to develop a structure which they can use with easiness.
My idea:
have a front sheet with a summary from activities and charts
let volunteers duplicate a template event cost and revenue and add their c&r
Result would have as much sheets as many Events and Charity or Fundraising events/campaign.
But, since the number of sheets is unknown till the end of the year, how can I have a summary sheet?
E.G. How can I sum all costs and all rev? Can I query to search in **all existing sheets the cell that follows an exact string (e.g. Total Rev)?**
You can write an Apps Script - a Google Script service based on Javascript
It is relatively simple to learn and use and it will allow you to loop dynamically through all the sheets without knowing in advance how many there will be.
The following sample script iterates through all sheets minus the master sheet of the spreadsheet to which it is bound and sums the values of the cells "A10" (if this is the cell where you have your costs) together. Finally it sets the value of the sum into the cell "A10" fo the master sheet.
function myFunction() {
var ss=SpreadsheetApp.getActiveSpreadsheet();
var sheets=ss.getSheets();
var sum=0;
for (var i=0; i<sheets.length; i++){
if(sheets[i].getName()!="Master"){
var value=sheets[i].getRange("A10").getValue();
sum=sum+value;
}
}
ss.getSheetByName("Master").getRange("A10").setValue(sum);
}
If you take some time to get familiar with Apps Script, you will be able to easily adapt the sample above to your needs.
I would recommend that the volunteers don't fill out anything on the sheet at all.
You can collect all you need from the volunteers via a google Form. That form will dump all the data into a single tab in google sheets from which it will be easy to analyze and summarize the data that you want to see and share with the whole team.
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().
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();}
The title sums it up pretty well. I need a cell of my document to reflect the last time any cell in the document updated. "=now()" doesn't work, because now() is evaluated any time the sheet is evaluated - even if there is no change. This means that even the simple act of hitting the browser's reload button causes now() to update its cell - TWICE!
I'd rather not use the onEdit trigger in script, because that would require that I add that script to 1000+ sheets. I already have a way to edit document through the python sheets API, so it would be fairly easy to automatically add the expression wherever I need it.
Volatile spreadsheet functions are not suitable for timestamps, for the reason you stated.
Use a trigger. You don't need to add a script to each sheet. A single stand-alone Google Apps Script can automatically install an "on edit" trigger for multiple spreadsheets, using forSpreadsheet(key) method. Example:
var ids = ['ss_id1', 'ss_id2', ... ]; // array of spreadsheet IDs
for (var i = 0; i < ids.length; i++) {
ScriptApp.newTrigger('timestamp').forSpreadsheet(ids[i]).onEdit().create();
}
function timestamp(e) {
e.source.getActiveSheet().getRange(1, 1).setValue(new Date());
}
Now, whenever one of the listed spreadsheets is edited, the cell A1 of the sheet that was edited in it will have the time of the edit.
This probably won't work for 1000 triggers, because of current limitations of 20 triggers per user per script. Looks like you'll need 50 copies of the stand-alone script, which is a stretch but still manageable.
Another alternative is to run a scheduled Google Apps Script that retrieves "last modified" dates of spreadsheets in the directory (using DriveApp) and edits those in the spreadsheets.
Yet another is to give up. Maybe you don't need a cell to hold information that is already available in spreadsheet interface, "last edited".