![](/img/trans.png)
[英]copy a value from one cell to another cell per row as “value” in Google sheet
[英]getting the value of a cell from another sheet with a fixed column and a variable row
我有一個非常簡單的谷歌應用腳本,我需要從另一個谷歌表中獲取一個單元格的值。 單元格始終具有相同的列(“A”),但行將根據傳遞給腳本的數字而有所不同。 我曾嘗試將 IMPORTRANGE 和 INDIRECT 與字符串變量一起使用,但我總是收到解析錯誤或名稱? 運行時出現錯誤或某種類型的語法錯誤。
有人會幫助我了解指定 setFormula 的正確方法嗎?
具體來說,我試圖讓以下 appscript 行在一個函數中工作,而不是對第 7 行進行硬編碼,我有一個行號變量(出於保密目的,我在 url 中有“xxx”):
電子表格.getCurrentCell().setFormula('=IMPORTRANGE("https://docs.google.com/spreadsheets/d/xxxxxx/edit#gid=xxxxxx","Videos!A7")');
我嘗試了幾次迭代,包括:
var sheetname = "Videos!A";
var row = "7";
var filenameRange = sheetname.toString()+row.toString();
spreadsheet.getCurrentCell().setFormula('=IMPORTRANGE("https://docs.google.com/spreadsheets/d/xxxx/edit#gid=xxxx","Videos!Arow")');
spreadsheet.getCurrentCell().setFormula('=IMPORTRANGE("https://docs.google.com/spreadsheets/d/xxxx/edit#gid=xxxx","Videos!A"&row)');
spreadsheet.getCurrentCell().setFormula('=IMPORTRANGE("https://docs.google.com/spreadsheets/d/xxxx/edit#gid=xxxx",INDIRECT("A"&row.tostring())');
謝謝你。
為此,更換
spreadsheet.getCurrentCell().setFormula('=IMPORTRANGE("https://docs.google.com/spreadsheets/d/xxxx/edit#gid=xxxx","Videos!Arow")');
和
spreadsheet.getCurrentCell().setFormula('=IMPORTRANGE("https://docs.google.com/spreadsheets/d/xxxx/edit#gid=xxxx","Videos!A' + row + '")');
基本上,如果您使用單引號'
來分隔公式字符串,則需要通過以下方式將靜態字符串與變量分開
'
+
連接'
並繼續靜態字符串的其余部分
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.