Google App Script 中的 SpreadsheetApp 服务可以读取、创建、修改 Google Sheet。
例如下方代码,SpreadsheetApp.getActiveSpreadsheet()方法得到当前表格文件对象(Spreadsheet),currentSpreadsheet.getActiveSheet()方法得到当前工作表对象(Sheet),currentSheet.getCurrentCell()得到当前活动单元格对象(Range),再通过单元格对象的getValue方法获取到活动单元格的值。

function logCurrent() {
  let currentSpreadsheet = SpreadsheetApp.getActiveSpreadsheet()
  let currentSheet = currentSpreadsheet.getActiveSheet();
  let currentRange = currentSheet.getCurrentCell();
  console.log(currentRange.getValue());
}

由小到大,可以把 Google Sheet 分为 Range、RangeList、Sheet、Spreadsheet。

Range

Range 是 Google Sheet 里的最小元素,表示单元格的区域,可以是一个单元格或者是一组单元格
当是一个单元格时可以用getValue()方法获取单元格显示的值,返回字符串;当是一组单元格则需要用getValues()来获取值,返回一个二维数组,第一层为行,第二层为列。

如下图,data最终的值为[[1,2],[3,4]]
spreadsheetapp1.JPG

function logData() {
  let sheet = SpreadsheetApp.getActiveSheet();
  let range = sheet.getDataRange()
  let data = range.getValues();
  console.log(data);
}

- 阅读剩余部分 -

[Google App Script][1] 里的函数可以在 Google Sheet 的公式里直接调用,例如可以自定义一个DOUBLE函数,当输入公式=DOUBLE(A1)将 A1 的值乘以二倍后返回,通过自定义函数可以实现默认函数不支持的功能。
![custom-function.jpg][2]

function DOUBLE(input) {
  return input * 2;
}

在公式里使用自定义函数时,系统先会自动处理传入的值然后再作为参数传入。例如=DOUBLE(A1:B1),最终input的值会是一个二维数组[[1,2]],所以需要在函数里添加处理数组的方法。

- 阅读剩余部分 -

工具:Google Indexation Tester
使用方法:

  1. 访问工具链接,会出现如下图提示,点击“制作副本”,然后会在你的Google表格里创建一个表格
    googleindexchecker
  2. 在B列里输入你要测试的网址,然后表格右侧选择“Run”,此时就开始自动测试了。可以在“Indexed URLs”和“Non-indexed URLs”里分别查看已收录和未收录。
    googleindexchecker
  3. 注意:
    1. 测试新的网址请先选“Reset”清除已存在的结果
      googleindexchecker
    2. 默认支持一次测试1000个网址
    3. 下一次使用此工具直接到你Google表格里,进入Google Indexation Tester表格即可
    4. 如果工具出现错误请尝试重新“制作副本”
    5. 工具可能有时效性,注意抽查结果是否正确

详细介绍:https://www.greenlanemarketing.com/tools/google-indexation-tester/