Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
247 views
in Technique[技术] by (71.8m points)

Google Sheets: Function in script editor return different value in google sheets

I am new with Google Sheets Script Editor. I am trying to get a function that returns how many time a word (in this case Mother) is present in a Bing website search. So I try this code:

function myFunction112() {
  const url = "https://www.bing.com/search?q=“Not all of us can do great things. But we can do small things with great love.”";
  const html = UrlFetchApp.fetch(url).getContentText();
  const numberOfOcurrencies = (html.match(/Mother/g) || []).length;
  console.log(numberOfOcurrencies);
  return numberOfOcurrencies;
}

The problem is that in Console it shows 18 for numberOfOcurrencies that is correct, but in my google sheet return 0. As you can see in the images below.

Script editor

Google sheet

I call my function myFunction112 to make sure no other function has the same name. How can I make my function return the same value that shows in console?

Many thanks.

question from:https://stackoverflow.com/questions/65852470/google-sheets-function-in-script-editor-return-different-value-in-google-sheets

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Supported services Notes
Cache Works, but not particularly useful in custom functions
HTML Can generate HTML, but cannot display it (rarely useful)
JDBC
Language
Lock Works, but not particularly useful in custom functions
Maps Can calculate directions, but not display maps
Properties
Spreadsheet Read only (can use most get*() methods, but not set*()).Cannot open other spreadsheets (SpreadsheetApp.openById() or SpreadsheetApp.openByUrl()).
URL Fetch
Utilities
XML

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...