Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

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

google apps script - Adding a property to an Html template gives error "Object does not allow properties to be added or changed"

I am trying to retrieve the data from my Google Spreadsheet, but when I try to add the data object to my htmlTemplate object, I receive the error

'Object does not allow properties to be added or changed'

My code is pretty simple:

function showDialog() {
  var htmlTemplate = HtmlService.createHtmlOutputFromFile('index');

  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheets()[0];
  var range = sheet.getDataRange();
  var values = range.getValues(); //get the spreadsheet data

  htmlTemplate.data = values; // error here
  ...
}

Could anyone tell me what is wrong with this?

See Question&Answers more detail:os

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

1 Answer

0 votes
by (71.8m points)

Instead of createHtmlOutputFromFile(filename) use createTemplateFromFile(filename)

The above because the first returns a HtmlOutput object which not allow to add properties while the second returns a HtmalTemplate which allows to add properties.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...