How to prevent GOOGLEFINANCE from recalculating? - google-apps-script

I'm using a GOOGLEFINANCE formula, but it keeps updating. I would like it to stay a fixed amount once it has been calculated the first time but I can't seem to figure out a way to do that. I tried Googling for the answer but came up empty-handed. I went to File > Spreadsheet Settings > Calculation, but there doesn't seem to be an option there to prevent recalculations, there only exist options to delay them.
It seems that feature is not built into Google Sheets. But maybe someone who is really good at formulas or a script. Can think of a super smart way to do it with a formula or a script?

There is no way to stop a Google Sheets formula, including those that use GOOGLEFINANCE function to recalculate.
You might replace the formula by it's result. One simple way to do this is by doing copy-paste as value only.
P.S. GOOGLEFINANCE data can't be retrieved by Google Apps Script.
Related
Pulling current price change % (Google Finance) with Google Apps Script

Related

How to solve the limitation of IMPORTRANGE formula in google sheet?

I have 50 google sheet files for 50 students. They need to key in their answers in their own google sheet file when they are asked to do so. I have a main google sheet to consolidate their data by using IMPORTRANGE formula. This is my formula:
=QUERY({IMPORTRANGE(...);IMPORTRANGE(...);IMPORTRANGE(...);...},"Select * where Col1 is not null")
I will have 50 IMPORTRANGE in the formula. So as expected, the main google sheet is very lag when the 50 students start to key in their answers at the same time. Sometimes, the formula will show #Value when all the students started to answer the questions at their own google sheet file. I need to keep refreshing the main google sheet so that the data will come out, but it will disappear again in a short while then I need to refresh it again (although it will settle down once most of the students finished answering the questions).
I know that using IMPORTRANGE is really not an efficient way to consolidate their answers in main google sheet file but I don't have other better way.
I tried to write a script so that they can send in their data by clicking the button assigned with the script. However, all the students need to go through the authorization process when they run the script for the first time. They don't know how to proceed when they saw the authorization process (not very good in using computer).
May I know is there any ways or tricks that I can use to solve the IMPORTRANGE issue? Or there are some way to write the script where we are not required to go through the authorization process when we run the script for the first time?
Hope to get some advice and help on this as I couldn't find a better way from Google already. Any help will be greatly appreciated!
If I understood correctly what you are looking is that your spreadsheet show in real-time the data being entered simultaneously on 50 different spreadsheets. I'm afraid that Google Sheets is not the right tool for what you are trying to do the way that you are trying to do it. Basically you have two options : change it or use a different tool.
It's not a good idea to have and array of multiple IMPORTRANGE functions that are being edited simultaneously because while the official docs says that IMPORTRANGE functions are updated every 30 minutes when the source and the spreadsheet having formula are opened at the same time the import is done practically immediately and could happen multiple times during the recalculation making causing it to start over an over again.
Replacing the above array by script might help only if you are open to not have the destination spreadsheet updated on real time as scripts are slow.
Replacing the above array by a program that uses the Google Sheets API also might help only if you are open to not have the destination spreadsheet updated on real time as the spreadsheet refresh.
Regarding running a script without requiring authorization that is only possible when using simple triggers and / or removing all the scopes that require authorization to run. Please bear in mind that you might create installable triggers to run other using the authorization of the user who creates them.
Related
Combining multiple spreadsheets in one using IMPORTRANGE
Why do two users sometimes see different values from importrange?
Multiple IMPORTRANGE
Using that many IMPORTRANGE formulas is definitely a bad idea. What I'd suggest you to do:
keep a list of all your student spreadsheet in your main document
write a script that will browse through all of the spreadsheets from that list and copy/paste values into your main document
create a time based trigger that will run the script every X minutes (or hours), depending on how accurate you want the results to be
This is a simple solution, but efficient. Depending on the amount of data and number of students/spreadsheets you may consider other solutions (like writing a cloud function that will do the same as the script) but I think this will work for your use case

Can I use Google Apps Script instead of Formulas for doing calculations on a spreadsheet?

Is Google Apps Script faster than FORMULAS for calculating sum or
sumif in a spreadsheet which has around 10,000 rows?
How does FORMULA work?
I know Google Apps Script executes its code in the cloud, but is there any way for that to work client-side just like JavaScript?
Is Google Apps Script faster than FORMULAS for calculating sum or
sumif in a spreadsheet which has around 10000 rows?
No
How does FORMULA work?
Client side, can cause desync issues but refreshing the page brings you back to what everyone else sees. So there is actually a server side and client side execution of these formulas to a certain extent
I know Google Apps Script executes its code in the cloud, but is
there any way for that to work client-side just like JavaScript?
No

Importrange function - what is the latest maximum data size that can be used? Changed late March

Google sheets changed the size of data that can be imported using the 'importrange' function in late March. We want to write a formula that can search through all our sheets and identify any that will be affected by Google's latest change.
We know there has been a change, as Importranges we had previously setup, are now returning "... to large" type error.
It appears to a limit of data size, not cells - as we experienced the issue on importrange of only 2 columns, but one contained large amount of HTML code in each cell.
Does anyone know what the data size limit is?
If not, then does anyone have an idea for best way to write a script that can find the limit?
Or next step will be to write a script that can search through our 'network analysis' sheet (sheet/tool that shows all Google sheets that are connected by importrange), and identify those with the importrange issue.
FYI - Google appears to have changed quite a bit relating to Google sheets and apps script.
a) We lost the ability to save changes in a sheet (making it basically unusable), which we think is related to having >50 importranges referencing that sheet (google support advised to avoid >50 importranges going to one sheet).
b) Other change we noticed is that google apps script can definitely now run for longer than the previous limit of 5min. We previously were seeing some scripts, sometimes running >5min, all the way up to a max of 30min. But now we see it consistently on some scripts. We built a tool, that can automatically get a script to 'run again' if it did not complete last time. We have had to tweak that 'run again script', to ensure it does not try to run the script again within 30min of the first run, to ensure that first script is definitely still not running.

Delay in changing Google Spreadsheet content via Google apps Script?

I am totally new to Google-apps-script and this may be very poor question
I am making a basic setup using google forms and google apps script
From the responses of form I change my content in Google Spreadsheet accordingly
For example my query from form needed 10000 records to be selected and produced in whole another spreadsheet
I just wanted to know that is there some kind of delay introduced when I set and get values of any cell of spreadsheet on such a large scale? If so on what it depends and how as a programmer can I remove or optimize them?
Thanks is advance!
The Best Practices article by Google is the primary reference for this. The most important advice is to minimize the number of calls to spreadsheet methods by batching operations. So, select a range that contains all the records you need, get them all at once with getValues, process without further interaction with the spreadsheet, and output the result using setValues.
If you follow this advice, 10000 records is still a reasonable amount of data to process by a script.

How to use ImportXML in a Google Script?

Scenario:
I am trying to use Google spreadsheet to do something like this:
I've a set of Blog URL's (more than 50) for which I want to fetch title
Currently I am using the formula: ImportXML(A2,"//h1[#class='entry-title']" )
The Problem w/ this approach is that ImportXML calls are limited to 50 per spreadsheet and I've more than 50.
I browsed/searched - found out that we can use ImportXML calls in google apps script but did not found any example.
I found this: https://developers.google.com/apps-script/articles/XML_tutorial but I was hoping to use ImportXML function.
Can anyone describe or point to a resource where they have used ImportXML in a google apps script? Thanks!
I would use a few spreadsheets, then pull the results together into a master spreadsheet, or are you doing >1000 or so. If you have lots, the XML_tutorial link you have is the place to start.
But last time I checked, google-apps-script does not support google spreadsheet functions, if I remember, the feature request to support all spreadsheet functions in GAS was rejected.