回答編集履歴
2
表示ダイアログの戻り値についての追記
test
CHANGED
@@ -35,3 +35,50 @@
|
|
35
35
|
こんな感じでいけました。
|
36
36
|
スプレッドシートのメッセージボックスとしてHTMLを指定し、そのHTML側でクリップボードにコピーするスクリプトを実行するという形になります。
|
37
37
|
|
38
|
+
---
|
39
|
+
文字列のコピーだけではなく、「はい」「いいえ」の選択で何かしらの処理を行いたい場合
|
40
|
+
```GAS
|
41
|
+
function copyToClipbord(){
|
42
|
+
var htmlOutput = HtmlService.createTemplateFromFile("popup");
|
43
|
+
htmlOutput.copytext = 'コピーする"文言"を設定する';
|
44
|
+
var html = htmlOutput.evaluate();
|
45
|
+
|
46
|
+
var ss = SpreadsheetApp.getActiveSpreadsheet();
|
47
|
+
ss.show(html); //メッセージボックスとしてを表示する
|
48
|
+
}
|
49
|
+
|
50
|
+
function dialogResult(result) {
|
51
|
+
if (result =='YES') {
|
52
|
+
Browser.msgBox('はいが押されました');
|
53
|
+
} else if (result =='NO') {
|
54
|
+
Browser.msgBox('いいえが押されました');
|
55
|
+
}
|
56
|
+
}
|
57
|
+
```
|
58
|
+
```HTML
|
59
|
+
<!DOCTYPE html>
|
60
|
+
<html>
|
61
|
+
<head>
|
62
|
+
<base target="_top">
|
63
|
+
</head>
|
64
|
+
<body>
|
65
|
+
<h2>コピーしますか?</h2>
|
66
|
+
<!--<input type="hidden" id="copyText" value="<?=copytext ?>" />-->
|
67
|
+
<button type="button" onclick="copyText(<?=copytext ?>)">はい</button>
|
68
|
+
<button type="close" onclick="returnResult('NO')">いいえ</button>
|
69
|
+
|
70
|
+
<script>
|
71
|
+
function copyText(txt) {
|
72
|
+
navigator.clipboard.writeText(txt);
|
73
|
+
returnResult('YES');
|
74
|
+
};
|
75
|
+
|
76
|
+
function returnResult(result) {
|
77
|
+
google.script.run.dialogResult(result);
|
78
|
+
google.script.host.close();
|
79
|
+
}
|
80
|
+
</script>
|
81
|
+
</body>
|
82
|
+
</html>
|
83
|
+
```
|
84
|
+
このようにボタンが押された時にスクリプトを呼び出すようにし、そこで押されたボタンにより処理を行うような形にできます。
|
1
ソース変更
test
CHANGED
@@ -18,13 +18,11 @@
|
|
18
18
|
</head>
|
19
19
|
<body>
|
20
20
|
<h2>コピーしますか?</h2>
|
21
|
-
<input type="hidden" id="copyText" value="<?=copytext ?>" />
|
22
|
-
<button type="button" onclick="copyText()">はい</button>
|
21
|
+
<button type="button" onclick="copyText(<?=copytext ?>)">はい</button>
|
23
22
|
<button type="close" onclick="google.script.host.close()">いいえ</button>
|
24
23
|
|
25
24
|
<script>
|
26
|
-
async function copyText() {
|
25
|
+
async function copyText(txt) {
|
27
|
-
var txt = document.getElementById('copyText').value;
|
28
26
|
navigator.clipboard.writeText(txt);
|
29
27
|
google.script.host.close();
|
30
28
|
};
|