Javascript 使用Google Apps脚本将对话框中输入字段的值返回到code.gs中的var
我一直在做一个谷歌工作表,它会在打开时触发一个对话框。我还没有弄清楚如何从code.gs中的输入字段中获取变量的值 我一直在寻找教程和代码示例已经有一段时间了,但还没有找到任何可以帮助我理解如何完成这项工作的东西 现在。。。在这种情况下,我只需要从对话框中的日期选择器获取日期。当单击按钮从code.gs运行函数时,我想知道如何将日期选择器中的值输入到函数中 到目前为止,我得到的是: code.gs:Javascript 使用Google Apps脚本将对话框中输入字段的值返回到code.gs中的var,javascript,google-apps-script,google-sheets,Javascript,Google Apps Script,Google Sheets,我一直在做一个谷歌工作表,它会在打开时触发一个对话框。我还没有弄清楚如何从code.gs中的输入字段中获取变量的值 我一直在寻找教程和代码示例已经有一段时间了,但还没有找到任何可以帮助我理解如何完成这项工作的东西 现在。。。在这种情况下,我只需要从对话框中的日期选择器获取日期。当单击按钮从code.gs运行函数时,我想知道如何将日期选择器中的值输入到函数中 到目前为止,我得到的是: code.gs: function optionOverlay() { var html = HtmlServ
function optionOverlay() {
var html = HtmlService.createHtmlOutputFromFile('overlayHTML')
.setSandboxMode(HtmlService.SandboxMode.IFRAME)
SpreadsheetApp.getUi()
.showModalDialog(html,' ')
}
function blankSheet() {
// The code below activates the Schedule Template and creates a duplicate of the blank template sheet.
var ss = SpreadsheetApp.getActiveSpreadsheet();
var st = ss.getSheetByName("Schedule Template");
st.activate()
SpreadsheetApp.getActiveSpreadsheet().duplicateActiveSheet();
// This changes the contents of the cell (I1) to the date from the dialog box.
var dialogDate = ?????
SpreadsheetApp.getActiveSheet().getRange('I1').setValue(dialogDate);
// This changes the new sheet's name to the date range of the week [based on cell (I2)].
var dateRange = SpreadsheetApp.getActiveSheet( ).getRange("I2").getValue();
SpreadsheetApp.getActiveSpreadsheet().renameActiveSheet(dateRange);
}
<h1>Create new schedule for the week starting on: </h1>
<input type="date" name="datePicker" id="datePicker" />
<button onclick="google.script.run.blankSheet()">Create schedule all new schedule</button>
<button onclick="google.script.run.copyLast()">Use last week as template</button>
</div>
overlayHTML:
function optionOverlay() {
var html = HtmlService.createHtmlOutputFromFile('overlayHTML')
.setSandboxMode(HtmlService.SandboxMode.IFRAME)
SpreadsheetApp.getUi()
.showModalDialog(html,' ')
}
function blankSheet() {
// The code below activates the Schedule Template and creates a duplicate of the blank template sheet.
var ss = SpreadsheetApp.getActiveSpreadsheet();
var st = ss.getSheetByName("Schedule Template");
st.activate()
SpreadsheetApp.getActiveSpreadsheet().duplicateActiveSheet();
// This changes the contents of the cell (I1) to the date from the dialog box.
var dialogDate = ?????
SpreadsheetApp.getActiveSheet().getRange('I1').setValue(dialogDate);
// This changes the new sheet's name to the date range of the week [based on cell (I2)].
var dateRange = SpreadsheetApp.getActiveSheet( ).getRange("I2").getValue();
SpreadsheetApp.getActiveSpreadsheet().renameActiveSheet(dateRange);
}
<h1>Create new schedule for the week starting on: </h1>
<input type="date" name="datePicker" id="datePicker" />
<button onclick="google.script.run.blankSheet()">Create schedule all new schedule</button>
<button onclick="google.script.run.copyLast()">Use last week as template</button>
</div>
为从以下日期开始的一周创建新计划:
创建计划所有新计划
使用上周作为模板
我已经看过很多关于在贬值的ui服务中创建jQuery日历和事件处理程序的内容,但是没有看到关于如何使用HtmlService从一个地方到另一个地方获取数据的内容。在这一点上,我很困惑,我希望任何方向都可以。要从输入标记中获取一个值,可以使用DOM方法
getElementById('idName')
和元素的value
属性
<input type="date" name="datePicker" id="datePicker" />
<button onclick="sendInputToGS()">Create schedule all new schedule</button>
<script>
window.sendInputToGS = function() {
var theDate = document.getElementById("datePicker").value;
google.script.run.blankSheet(theDate)
}
</script>