【问题标题】:Been trying to automate the Find and Replace in Google Sheets but did not work一直在尝试自动化 Google 表格中的查找和替换,但没有奏效
【发布时间】:2020-08-29 14:55:08
【问题描述】:

我的工作表是来自数据库的查询表。其中一些包含html十六进制代码颜色,我需要在每次刷新时手动使用编辑>查找和替换。

我对 Google App Script 很陌生,一直在尝试使用以下代码:

function Clearcode() {
  var lookupone = new RegExp(/{color:#.{7}/);
  var rep = "";
  var spreadSheet = SpreadsheetApp.getActive();
  var querySheet = spreadSheet.getSheetByName("QUERY");
  var lastRow = querySheet.getLastRow();
  var lastColumn = querySheet.getLastColumn();
  var data = querySheet.getRange(2, 1, lastRow-1, lastColumn).getValues();
  var textfinder = querySheet.createTextFinder(lookupone);
  var found = textfinder.replaceAllWith(rep);
  return (found);
}

然而,当我在工作表中运行此功能时,它不起作用。有什么想法吗?

附:我计划通过创建类似的函数来消除十六进制代码的“[color]”部分。

P.S.2 我已按照您的要求附上了一张表格的快照。红线只是为了数据的机密性。该行下方只是一个普通文本。

【问题讨论】:

  • 你能分享一份你的工作表样本吗?
  • 提供数据的屏幕截图或 ascii 表
  • 我已经上传截图了!

标签: regex google-apps-script google-sheets


【解决方案1】:

关注types!

querySheet.createTextFinder("\\{color:#?.{0,6}\\}")//only 6 characters
  .useRegularExpressions(true)
  .replaceAllWith("")

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-26
    • 1970-01-01
    • 1970-01-01
    • 2022-08-02
    • 1970-01-01
    相关资源
    最近更新 更多