Automatically update embedded Google Sheets Chart in Docs? - google-apps-script

I have inserted a chart into a Google Doc, but would like to make it update automatically instead of having to manually open the Doc and press the floating update buttons.
So far I have found no way to do this beyond writing a script to replace each one every time - which I have not yet felt strong enough to do.
How can an embedded chart be updated automatically?

Google Docs doesn't support the proper way of linking and embedding objects like MS Office does. I haven't seen any real solution as yet.

I found several answers from this forum you might want to try:
Using XML Gadget for Charting:Steps if you would like to try out;
Go to your google spreadsheet (or googgle form data).
go to Menu>Insert>Gadget
click "chart" & select chart you like & "add to spreadsheet"
key-in all the chart setting required by the Gadget
click "apply & close"
After the chart populated, point your mouse to the left corner of chart, click "gadget"
You'll see "Get Query data source"-item a
and "Get XML" - item b
click the item b, example "http://www.google.com/ig/modules/image-bar-chart.xml"
Go to google "site" and "insert" > "more gadget"> "add gadget by url"> paste the item b, http://www.google.com/ig/modules/image-bar-chart.xml
You'll need to provide the data source in the pop-up windows, paste the link of item a and key-in all necessary setting. (refresh interval 1, 5, 30mins- set here)
save & done.
Using ARRAYFORMULA to make sure that the charts would be updated with the new information. Sample is in this site.
I'm not entirely sure if this is useful but since you're doing scripting, you might as well check Read and write data in Firebase from Apps Script.

Found a hint at github:
Yes, that is correct, published charts in Google Sheets only update 5 minutes after a change was made.

Related

App Script authorizations associated with Google Sheets

I have managed to incorporate an app into a Google sheet I was able to copy from a tutorial video. The app provides a Custom Menu in the sheet that allows a user to conduct a search of content across the sheet.
The sheet, with editor access and Custom Menu showing, is available here:
https://docs.google.com/spreadsheets/d/1fl2B9yrZA75Vm5KwVsLsZ4K2_GUYO35LQLYxDcSoauY/edit?usp=share_link
and it works fine even if I may do some more formatting.
The sheet is available via the Search Test button near bottom right on this page:
https://www.victoriasforestryheritage.org.au/resources/records.html
but, as you will see, I am unable to set authorizations in the back end so that any user on the front end can access the sheet with the custom menu showing so they can search the data. The link above shows the sheet, but without the Custom Menu.(The custom Menu appears to work if I prove Editor access, but obviously I do not wish to do that)
The use of Apps Script is totally new to me, and I have searched widely for help, but obviously have found no solution. I read what I think are the relevant Google documents but I simply do not have the depth of understanding to interpret them.
In summary, I wish any user of the website to be able to access a linked google sheet and be able to search that sheet using the Apps Script created Custom Menu .
I am functional with HTML and CSS and just beginning to try and learn some JavaScript. In other words you are corresponding with a relative novice.
I have tried different file access levels as indicated above, I have looked through Apps Script authorization process but frankly I have trouble understanding how and where the Script links to the sheet.
Any help would be much appreciated.
Richard

Google Sheets: Why can't I insert a link (to anything) in a cell containing a formula

In any Google Sheet, select a cell containing a formula, for example, =SUM(1,1). You'll see that both the Insert->Link menu
and the toolbar button for Insert Link (Ctrl + K) are disabled.
Why is that?
PS:
I've spent considerable time on Google, but I haven't found this issue mentioned anywhere.
This problem occurs irrespective of whether the formula has been manually typed in the cell or been populated through Apps Script.
This is intended behaviour
If you press Ctrl+K when a cell with a formula is highlighted you get the following message:
Not sure if this applies to you, but I solved my problem after coming here. I realized that where I was trying to change the links was actually an "importrange" of another file. So I have a daily sales ticker that feeds out to our salespeople, but I don't want them to "see" my live file and accidentally make changes. So I use "importrange" to show just one page of my big file to the salespeople and if they accidentally make a change, it doesn't affect my original formulas. I was trying to update the links on the "shared version". Once I went to my original file, I could update the links as expected. It was ODD though that I was able to delete the link on the shared page. Just couldn't edit it or create a new link there.

Moving an item from one Google form to a new Google form using google apps script

When editing a Google form manually, you can usually click on an item, and on the side appears a menu, which includes the button "import questions". This button is very useful for me as it allows me to collect questions from past Google forms and import them to new Google forms.
But I'm looking through the Forms documentation, and I can't figure out how to do this via Google apps script programatically.
Here is the documentation:
https://developers.google.com/apps-script/reference/forms/form
The closest thing to what I want is the .moveItem() method, which moves an item from one spot in a form to another. But it only works within the same form. I want to know if I could do it across forms. And ideally, instead of moving the item, it would make a copy of the item in the new form.
I considered the .getItems() method, but there doesn't seem to be a general .addItem() method I could use on the new form. Would I have to go through the painstaking process of having to identify each item type, and specify how the details of each one should be copied to the new form, including things like point values of a question and whether or not the question is required?
I want to import from forms that have all kinds of content: video, images, multiple choice questions, grid questions, number scale questions, etc. I feel that if I have to specify the details of each item type, it would take too long, and I would be bound to miss something or run into an error that may be impossible to solve. Is there not an easier way?
And if specifying each item type is what I have to do to import everything properly, has someone else created that code already that I can re-use?
Issue:
In the current stage, unfortunately, it seems that Forms Service cannot copy all items. Ref1, Ref2 Ref3. And, unfortunately, moveItem can be used for the same Google Form as you say.
Workaround:
In your situation, as a workaround, how about copying the source Google Form? And, when there are some items you want to remove, you can remove them. I thought that this process can be achieved by Google Apps Script.
But, I'm not sure about your actual Google Form. So I'm not sure whether this is a suitable method.
Future:
Recently, Google Forms API was announced. Ref When this API got to be able to be used, your goal might be able to be achieved by retrieving the object from Google Form. Unfortunately, I'm still not sure about the detail of it.

Data label Google spreadsheet Column chart

I have created a column chart in Google spreadsheet, but it is not showing data label explicitly.
I need data value to be shown on top of each bar of column chart. Currently, that is showing only as tool tip, but I require it to be always visible.
I have not used any script just created it directly, please provide some way either by script/direct to implement data labels. only direct / apps script but no java script as I only need to view it on my spreadsheet.
here is link of sheet: https://docs.google.com/spreadsheets/d/1a95DrTeLA52Xmycq3IUlWgfqASQWJQla7xEXx5-KWGE/edit?usp=sharing
You may have found the solution by now but just in case it might be helpful to others, here's my response.
Your sharing of sheet was useful in helping you with your question. Here are the steps to get the values for the data labels on the top of your columns.
Right click on the chart.
Click on Advanced Edit. (This will open a new window named "Chart Editor")
Click on "Customization" tab.
Drag the bar and keep going down until you see "Data Labels" with a drop down below it.
Click on the drop down. (This will open a list of options)
Choose "value" from this list of options.
Click "Update" and you'll see the change in your graph.
Let me know if you have any questions.
I figured out a solution. If you create a pivot table and graph that data, the values will show.

How to call a script in Google Spreadsheet above a frozen row?

Above a frozen row I want to put an image that is linked to a script; e.g. click the image and a script runs.
I can insert an image and add a script to it, problem: can only be
done under frozen row.
I can insert an image using =image("imageurl";2), I can even put a
hyperlink to this =hyperlink("url"; image("imageurl";2)) and this
works nicely but I can't call a script.
Any ideas on how to solve this?
How do you add UI inside cells in a google spreadsheet using app script? ... shows how to insert a drawing and link it to a script. Unfortunately, as you've found, floating images are not allowed in frozen rows or columns, so that technique breaks down if you must freeze rows. A quick search on the interwebs will show that this has been a long-term complaint about Google Sheets. (For instance.)
There are options, none of them ideal:
Use a custom menu function instead. That means users need to hunt a bit to find the menu option to kick your script, but it does stay in view no matter where they are.
Use the hyperlink & image work-around you've described, but use a published script url as the target. That will allow you to run a google apps script, indirectly.
Use a sidebar. OK, this isn't actually supported in Sheets yet - visit Issue 3162 and star it for updates.