Apps脚本提示对"Enter"或HTML确认做出反应 [英] Apps Script Prompt to react to 'Enter', or HTML Confirm

查看:86
本文介绍了Apps脚本提示对"Enter"或HTML确认做出反应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图弄清楚如何使用Apps Script在电子表格中获得提示,确定"为蓝色,您可以按Enter键(按ESC即可取消).

I'm trying to figure out how to get a prompt in a spreadsheet using Apps Script, where the OK is blue and you can just hit Enter (and esc. for cancel).

我尝试使用HTML的Confirm with HTML Service进行操作,该方法效果很好,但是到目前为止,如果没有其他类似的UI弹出窗口,我似乎无法使其正常工作.另外,我不知道该如何注册用户选择的内容(确定或取消),因为这需要确定接下来要执行的Apps脚本.有没有办法从HTML文件中传输变量以供脚本使用?

I tried playing with HTML's Confirm with HTML Service, which would work great, but so far I can't seem to get it to work without an additional UI pop-up of sort. Plus, I don't know how I would then register what was selected by the user (OK or CANCEL), as that needs to determine what Apps Script does next. Is there a way to transfer a variable from an HTML file to be used in the script?

p.s.我之所以需要它而不是本机的警报"或提示",是因为需要两次单击Tab才能到达确定"按钮,或者您只需要使用鼠标即可.这是一项非常重复的任务,最终会带来大量额外的点击.

p.s. The reason why I need this and not the native Alert or Prompt, is because it takes two Tab clicks to get to the OK button, or you just need to use the mouse. It's for a very repetitive task, and it ends up being a huge amount of extra clicks.

有什么想法吗?

推荐答案

不确定是否会满足您的要求,但是使用侧边栏面板显示确定/取消"按钮可以完成此任务.您可以通过烤面包消息显示任务/问题(这样您就不会在侧边栏的按钮上失去浏览器的关注,就像在模式框中那样).然后,由于侧边栏一直在显示,因此您可以按Enter或Tab并按Enter来选择先前集中显示的确定"或取消".

Not sure whether that will satisfy you, but using a sidebar panel to show the "OK/Cancel" buttons could do the job. You can display the task/question via toast message (so that you do not lose the browser's focus on the sidebar's buttons, as it would happen with modal boxes). Then, since the sidebar is being displayed all the time, you could just press enter or tab and enter to choose the previously focused "OK" or "Cancel".

我不确定如何连接主要功能,吐司消息和确定/取消"面板,但我想例如在工作表本身中存储一些数据就可以完成这项工作.

I am not entirely sure how to connect the main function, toast message and OK/Cancel panel, but I guess that storing some data for example in the sheet itself could do the job.

例如:您将"D5"单元格坐标存储在工作表中的某个位置,然后运行函数. Toast询问您是否要修改D5(使用存储的坐标).如果选择是,函数将运行,获取坐标并继续.

For example: you have "D5" cell coordinates stored somewhere in a sheet and you run function. Toast asks you if you want to modify D5 (using the stored coordinates). If you select yes, a function runs, takes the coordinates and proceeds.

这是非常复杂的,并且可能效果不佳,但是如果您的工作真的如此重复,则可以节省一些时间.

That's pretty complicated and probably monstrously uneffective but if your job is really so repetitive, it may save some time.

此处的示例表(HTML代码为

Here's an example sheet (HTML code is taken from some of my old scripts) and code for GS and HTML is also available below.

Code.gs

function onOpen() {

  var html = HtmlService.createHtmlOutputFromFile('sidebar')
  .setTitle('a test');

  SpreadsheetApp.getUi()
  .showSidebar(html)
  .createMenu('——MENU')
  .addItem('Test toast', 'openDialog')
  .addToUi();
}

// ok/cancel functions
function func_ok(){
   SpreadsheetApp.getActiveSpreadsheet().toast('ok');
  // do something
}

function func_cancel(){
  SpreadsheetApp.getActiveSpreadsheet().toast('cancel');
  // do something
}

// toast function
function openDialog() {
  SpreadsheetApp.getActiveSpreadsheet().toast('you can display some information here and confirm in via the panel');
}

sidebar.html

<div style='font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;background: linear-gradient(to bottom, #323232 0%,#ffffff 100%);padding-bottom:100%'>

<section style='background:#FFE599'>
<button onclick="google.script.run.func_ok();">OK</button>
<button onclick="google.script.run.func_cancel();">Cancel</button>
</section>

</div>


<!-- stylesheet -->
<style>

h4 {
margin:auto auto 10px auto;
border-bottom: 1px solid rgba(44, 44, 44, 0.3);
padding:3px 10px;
background: rgba(44, 44, 44, 0.1);
text-align:center
}

button {
background: #E5E5E5;
border:none;
border-bottom:2px solid #ccc;
border-radius:2px;
padding:3px 4px;
margin:4px 10%;
width:80%
}

button:hover {
background:#efefef;
cursor:pointer
}

section {
padding-bottom:5%;
margin: 0 2% 5% 2%;
border-radius: 2px;
box-shadow:0 1px 2px 1px #111111;
}
</style>

这篇关于Apps脚本提示对"Enter"或HTML确认做出反应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆