使用Google电子表格值在Google文档侧栏中下拉列表

时间:2016-11-09 03:48:51

标签: javascript html google-apps-script google-sheets google-docs

似乎没有太多的东西r.e.谷歌文档侧栏。

除了莫格斯达德所做的出色工作。

他的光标位置工具是我需要的1/2(How to poll a Google Doc from an add-on)。

我有一个google工作表模板,其中包含~200个可能的占位符,需要放入google doc,填充,然后填写PDF' d。

我似乎无法在任何地方找到如何将范围从谷歌表格转换为文档侧栏。这样在构建模板时,我可以设置一些变量动态下拉菜单,将正确的占位符放在光标位置。

任何人都能指出我正确的方向吗? (是的,我知道独裁者:P)

1 个答案:

答案 0 :(得分:1)

使用Google Apps脚本Spreadsheet service,首先打开电子表格然后获取范围,最后获取值。

示例:

/**
 * Get the values from a range speficied by the Spreadsheet ID and the range reference or 
 * name
 *
 * @param {'1FkUd199CS3U25bfb5WxP-Jy--qcgD4NTHYWNMw8AtiA'} id Spreadsheet id
 * @param {'Sheet1!A1:A100'} stringReference Reference string
 * @return 2D array with the values of the specified range
 */
function getSpreadsheetValues(id,stringReference){
  var ss = SpreadsheetApp.openById(id);
  var range = ss.getRange(stringReference);
  return range.getValues();
}