[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"blog-google-sheet的app-script中getrange-與-getdatarange的差異":3},{"id":4,"slug":5,"title":6,"description":7,"content":8,"date":9,"image":10,"imageAlt":6,"author":11,"categories":14,"path":17,"minRead":18},3504,"google-sheet的app-script中getrange-與-getdatarange的差異","google sheet的app script中getRange 與 getDataRange的差異","google sheet的app script中getRange 與 getDataRange的差異 沒想到會 […]","\u003Ch1>google sheet的app script中getRange 與 getDataRange的差異\u003C\u002Fh1>\n\u003Cp>沒想到會碰到google sheet的app script的需求，哈哈，時常耳聞如果有在使用google sheet的話app script會增加非常多助力，實際寫過還真的如此，類似Excel的巨集，但因為google api整合的很好，所以實際上能做非常多事情，今天就來記錄一下遇到的一些狀況。\u003C\u002Fp>\n\u003Ch2>如何取資料\u003C\u002Fh2>\n\u003Cp>使用app script在sheet中大多時間應該會去查找資料，跟資料庫不同，我們必須手刻查找的方式，就是一欄(column)一列(row)的去找，就會使用getRange 與 getDataRange這兩個函式。\u003C\u002Fp>\n\u003Ch2>getRange\u003C\u002Fh2>\n\u003Cp>主要功能就是指定資料範圍，可以選用A1標記或是R1C1標記。\u003Cbr \u002F>\n\u003Ca href=\"https:\u002F\u002Fdevelopers.google.com\u002Fapps-script\u002Freference\u002Fspreadsheet\u002Fspreadsheet?hl=zh-tw#getrangea1notation\">https:\u002F\u002Fdevelopers.google.com\u002Fapps-script\u002Freference\u002Fspreadsheet\u002Fspreadsheet?hl=zh-tw#getrangea1notation\u003C\u002Fa>\u003Cbr \u002F>\n舉例來說如下，以sheet中的第一欄第一列那格儲存格(cell)來說：\u003C\u002Fp>\n\u003Ch3>A1標記\u003C\u002Fh3>\n\u003Cpre>\u003Ccode>getRange(&#039;A1&#039;)  \u002F\u002F(欄位置,列位置) \u003C\u002Fcode>\u003C\u002Fpre>\n\u003Ch3>R1C1標記\u003C\u002Fh3>\n\u003Cpre>\u003Ccode>getRange(1,1,1,1)  \u002F\u002F(起始列,起始欄,欄數,列數) \u003C\u002Fcode>\u003C\u002Fpre>\n\u003Cp>在sheet上方可以看到每欄都有標記像是A~Z\u003Cbr \u002F>\n左側則有列數標記1 ~ 1000\u003Cbr \u002F>\n以此類推\u003Cbr \u002F>\n有幾種範圍指定方式，\u003Cbr \u002F>\n1.指定一個儲存格(cell)\u003Cbr \u002F>\n就是上述例子，規格就是先欄後列，所以就是getRange('A1')，如果是B20那就是getRange('B20')，用R1C1標記的話就getRange(2,20,1,1)，\u003C\u002Fp>\n\u003Cp>2.指定範圍\u003Cbr \u002F>\n將以上方式拓展成一個區域時的寫法如下，例如A1~C10，也就是會有3欄10列的狀況。\u003C\u002Fp>\n\u003Ch3>A1標記\u003C\u002Fh3>\n\u003Cpre>\u003Ccode>getRange(&#039;A1:C10&#039;)\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Ch3>R1C1標記\u003C\u002Fh3>\n\u003Cpre>\u003Ccode>getRange(1,1,3,10)\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Cp>當然你想要指定某欄或某列就要看你的資料長相如何來決定囉。\u003C\u002Fp>\n\u003Ch2>getDataRange\u003C\u002Fh2>\n\u003Cp>這個函式會指定這張分頁的所有資料(有資料的範圍)，並且回傳所有資料，像是以下\u003C\u002Fp>\n\u003Cpre>\u003Ccode>getRange(1, 1, sheet.getLastRow(), sheet.getLastColumn())\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Ch2>getRangeList\u003C\u002Fh2>\n\u003Cp>有個跟getRange很像的getRangeList，則是可以回傳多個範圍內的集合，效果不同。\u003C\u002Fp>\n","2023-04-27T20:00:31","\u002Fapi\u002Fproxy-image?url=https%3A%2F%2Fpost.billxu.net%2Fwp-content%2Fuploads%2F2023%2F04%2Fe8c116c7-f85f-465b-abdc-34e0dcb28b9f.jpeg",{"name":12,"link":13},"Chih Fan","http:\u002F\u002Fpost.billxu.net",[15],{"name":16,"slug":16},"office","\u002Fblog\u002Fgoogle-sheet的app-script中getrange-與-getdatarange的差異",1]