Google 脚本 - findText 未定义

问题描述 投票:0回答:0

我正在尝试为我的 Google 文档制作一个脚本,以便我可以根据段落开头的昵称(例如:“myNickname:blah blah blah”)格式化某些“聊天记录”部分中的特定段落。

我做了一个测试函数来测试 findText() 但是当我执行

test()
时,它返回这个错误:
ReferenceError: findText is not defined   test @ Code.gs:21

这是完整的脚本:

function onOpen(e) {
  DocumentApp.getUi()
  .createMenu("FORMATTING")
    .addItem("Test", "test")

  .addToUi();
}

function formatNickname(nickname, style) {
  nickname = nickname + ":"; // Dialogue is in a 'chat log' format, so it's displayed as "NICKNAME: Blah blah blah"

  let foundText = findText(nickname); 

  foundText.getText().setTextStyle(style);

  console.log(foundText); // Debug
}

function test() {
  formatNickname("BAB", findText("AA:").getText.getTextStyle()); // The second parameter is for debug reasons. AA is a character with a specific text style.
}

这是我的 appsscript.json:

{
  "oauthScopes": [
    "https://www.googleapis.com/auth/documents.currentonly",
    "https://www.googleapis.com/auth/documents"
  ],
  "timeZone": "America/Sao_Paulo",
  "dependencies": {
  },
  "exceptionLogging": "STACKDRIVER",
  "runtimeVersion": "V8"
}

我在我的用户设置中打开了 Google Apps Script API,如 this answer 中所述。

javascript google-apps-script google-docs google-docs-api
© www.soinside.com 2019 - 2024. All rights reserved.