我有一个 JavaScript 函数,它获取 src 值
<div>
<img src="theUrl" id="imgID" onclick="myImageUrl()" />
</div>
<script>
function myImageUrl() {
var q = document.getElementById(imgID).src;
google.script.run
.imageCell();
}
</script>
我似乎不知道如何将其传递到 Google Apps 函数中,以便我可以将图像 URL 实现到单元格中,例如
function imageCell() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var range = ss.getActiveRange();
range.setValue(q);
}
更新:
感谢阿米特,但除非我遗漏了一些东西,否则该值不允许使用保存的变量。我以两种方式运行
HTML
<div id="theImageUrl">
<img src="http://placekitten.com/100/100" id="theImageUrl" onclick="getImage()" />
</div>
<script>
function getImage() {
q = document.getElementById( 'theImageUrl ).src;
google.script.run.imageCell(q);
}
</script>
由我的 fiddle 验证Fiddle
服务器端
function imageCell(q) {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var range = ss.getActiveRange();
range.setValue(q);
}
*.setValue(q) 和 .setValue();
最佳答案
在 HTML 方面:
google.script.run.imageCell(q);
在服务器端:
函数 imageCell(q) { ...
关于javascript - 将 Javascript 变量传递给 Google 脚本函数 (Google Sheets),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29002585/