Sheet cell can successfully show the result of the formula I setup from myFunction() but failed when I input variable by using doGet(e) { }. It shows "#REF!" in the cell and "unresolved sheet name xx".
In this function, setFormula() can successfully show the result in sheet cell.
function myFunction() {
var ss1 = SpreadsheetApp.openByUrl("https://xxxxxxxxxxxxxxxxxxxxxxxxgid=0");
var sheet1 = ss1.getSheetByName("Sheet1");
var sheet;
sheet = 6;
var sheet = sheet.toString();
sheet1.getRange(6,9).setFormula(sheet + '!B1');
}
Later on, I followed the syndax of setFormula to setup as below, but somehow it not work. It shows "#REF!" in sheet cell.
function doGet(e) {
var shopname = e.parameter.shop1;
var shopname = shopname.toString();
var row = sheet.activate().getLastRow();
sheet.activate().getRange(row,9).setFormula( shopname + '!B1');
// sheet.activate().getRange(row,9).setFormula("'" + shopname + "'!" + "B1");
// sheet1.getRange(6,9).setFormula("'" + sheet + "'!" + "B1");
}