在对 getEditResponeURL 代码使用 Google 脚本时,我可以用特定文本替换 URL Link 吗?
Can I replace the URL Link with specific text when using Google Script for the getEditResponeURL code?
我使用以下代码将 Google 表格 URL 放入电子表格
但我想知道我是否可以用超链接 'EDIT FORM' 文本替换可能很长的 URL。
var formURL = 'https://docs.google.com/forms/d/(MY CODE)/viewform';
var sheetName = 'Responses';
var columnIndex = 8 ;
function getEditResponseUrls() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheetName);
var data = sheet.getDataRange().getValues();
var form = FormApp.openByUrl(formURL);
for(var i = 2; i < data.length; i++) {
if (data[i][0] != '' && data[i][columnIndex-1] == '') {
var timestamp = data[i][0];
var formSubmitted = form.getResponses(timestamp);
if (formSubmitted.length < 1) continue;
var editResponseUrl = formSubmitted[0].getEditResponseUrl();
sheet.getRange(i+1, columnIndex).setValue(editResponseUrl);
}
}
}
为了实现您想要的效果,您只需对代码进行以下更改:
var editResponseUrl = formSubmitted[0].getEditResponseUrl();
var formula = '=HYPERLINK('+'"'+editResponseUrl+'"'+',"EDIT FORM")';
sheet.getRange(i+1, columnIndex).setFormula(formula);
以上代码段使用表格中的 =HYPERLINK()
公式,以便能够创建 editResponseUrl
与 EDIT FORM
文本的超链接。之后,通过 Apps 脚本中的 setFormula()
方法使用此公式。
参考
我使用以下代码将 Google 表格 URL 放入电子表格 但我想知道我是否可以用超链接 'EDIT FORM' 文本替换可能很长的 URL。
var formURL = 'https://docs.google.com/forms/d/(MY CODE)/viewform';
var sheetName = 'Responses';
var columnIndex = 8 ;
function getEditResponseUrls() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheetName);
var data = sheet.getDataRange().getValues();
var form = FormApp.openByUrl(formURL);
for(var i = 2; i < data.length; i++) {
if (data[i][0] != '' && data[i][columnIndex-1] == '') {
var timestamp = data[i][0];
var formSubmitted = form.getResponses(timestamp);
if (formSubmitted.length < 1) continue;
var editResponseUrl = formSubmitted[0].getEditResponseUrl();
sheet.getRange(i+1, columnIndex).setValue(editResponseUrl);
}
}
}
为了实现您想要的效果,您只需对代码进行以下更改:
var editResponseUrl = formSubmitted[0].getEditResponseUrl();
var formula = '=HYPERLINK('+'"'+editResponseUrl+'"'+',"EDIT FORM")';
sheet.getRange(i+1, columnIndex).setFormula(formula);
以上代码段使用表格中的 =HYPERLINK()
公式,以便能够创建 editResponseUrl
与 EDIT FORM
文本的超链接。之后,通过 Apps 脚本中的 setFormula()
方法使用此公式。
参考