我有一個單元格 B2,它根據用戶的選擇顯示動態超鏈接,我想使用該單元格作為對我的腳本的參考(在按鈕上打開 url)。如何修改此腳本以從 B2 單元中獲取鏈接?
//change the value of url to your desired url.
function openUrl( url="https://google.com" ){
var html = HtmlService.createHtmlOutput('<html><script>'
'window.close = function(){window.setTimeout(function(){google.script.host.close()},9)};'
'var a = document.createElement("a"); a.href="' url '"; a.target="_blank";'
'if(document.createEvent){'
' var event=document.createEvent("MouseEvents");'
' if(navigator.userAgent.toLowerCase().indexOf("firefox")>-1){window.document.body.append(a)}'
' event.initEvent("click",true,true); a.dispatchEvent(event);'
'}else{ a.click() }'
'close();'
'</script>'
// Offer URL as clickable link in case above code fails.
'<body style="word-break:break-word;font-family:sans-serif;">Failed to open automatically. <a href="' url '" target="_blank" onclick="window.close()">Click here to proceed</a>.</body>'
'<script>google.script.host.setHeight(40);google.script.host.setWidth(410)</script>'
'</html>')
.setWidth( 90 ).setHeight( 1 );
SpreadsheetApp.getUi().showModalDialog( html, "Opening ..." );
}
uj5u.com熱心網友回復:
從I would like to use that cell as a reference to my script (which opens url on a button).和How can I modify this script in order to get the link from the B2 cell?,當你的腳本被修改時,下面的修改怎么樣?
從:
function openUrl( url="https://google.com" ){
到:
function openUrl(){
var url = SpreadsheetApp.getActiveSheet().getRange("B2").getValue();
參考:
- getRange(a1Notation)
- 獲取值()
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/452727.html
