简体   繁体   中英

Google Sheets Scripts and Trendlines

This question is first about scripts, because I am obviously missing something. I am looking for help actually just implementing them. When I go to the "script editor" I always have to create a new "project" and save it as something. Should the script not be attached to the spreadsheet?

But if I ignore that strange fact and I open the editor and copy and paste a nice script in there, how do I get it to run in my spreadsheet? Sometimes I can see that if I go back to the spreadsheet and refresh the page a new menu item appears, which makes me think that the script is running, but then where is that script saved? An overview of what is going on in Google Scripts would be awesome.

The overall problem that I am attempting to solve: I want my spreadsheets to be able to plot trendlines. I thought the solution would be to write a script and apply it to all spreadsheets. This ideal script would have a menu item for trendlines, and would allow me to select the data for which I need a trendline. Does anyone have any advice or even the scripts to do this? I am not a programmer but I can learn the basics for this if I need to. This feature really should exist. I can't remember ever making a scatterplot and not plotting the trend and equation. Thanks for the help.

First of all, you're asking a lot of questions.

As commented above by Zig Mandel, you need to read documentation first.

Here are some links for the documentation pages to get you underway:

Google Spreadsheet Documentation

Google Sheet Documentation

Google Range Documentation

I don't know how much experience you have or what sort of background you have, so it's hard to comment on what to do. A seasoned dev or techie would know which parts of the API he/she would use. Perhaps you can start with a small example such as colouring a range of cells.

In regards to copying and pasting the pre-made script:

The premade script could do anything. It's probably a bad example. Creating a menu item does NOT constitute the script being correct or even running. The menu will be created when the document opens, and will be in a function called "onOpen()."

Try starting a new project, and planning what you want to do. Play around with some features that seem like they could apply, such as getActiveRange(), getRange(), getSheets(), getActiveSpreadSheet(); just for starters.

In regards to a custom menu, try this (after you have some idea about what's going on):

https://developers.google.com/apps-script/guides/menus

For your exact problem, I couldn't help as I have done nothing with graphs in Google Apps Script, however you seem to be diving into the deep end and I think the above points will point you in the right direction.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM