【问题标题】:Is there a way in Google Sheets to track connected sheetsGoogle表格中有没有办法跟踪连接的表格
【发布时间】:2021-09-01 00:07:45
【问题描述】:

我为一家小公司维护内部数据。我们专门使用 Google 表格。我经常使用“importrange”功能,我想知道,有没有办法跟踪 A)到特定工作表的连接数和/或 B)列出连接的工作表?

我正在修改我的一些“核心”工作表,并希望确保将所有其他连接工作表迁移到新数据源。

例如,我有一个公司名册,我们称之为 SheetX。如果我重新设计 SheetX 并调用新的电子表格 SheetY,如何确保所有其他工作表现在都从 SheetY 导入数据。

【问题讨论】:

    标签: google-sheets google-sheets-formula


    【解决方案1】:

    这里是 AppsScript 函数,您可以使用它来枚举活动电子表格中任何 IMPORTRANGE 公式引用的所有 URL:

    function enumerateDependencies(){
      const ss = SpreadsheetApp.getActive()
      const sheets = ss.getSheets()
      const referencedUrls = []
      for(const sh of sheets){
        const formulas = sh.getDataRange().getFormulas().flat().map(formula=>formula.toUpperCase())
        
        const importRangeFormulas = formulas.filter(formula=>formula.match(/^=.*IMPORTRANGE\(/) )
        for(const formula of importRangeFormulas){
          const m = formula.match(/"(HTTPS?:\/\/.*?)"/)
          if(m && m[1]){
            if(referencedUrls.indexOf(m[1])<0){
              referencedUrls.push(m[1])
            }
          }
        }
      }
      console.log(referencedUrls)
    }
    

    【讨论】:

    • 非常感谢您的及时回复。你知道是否有办法扭转这个过程?
    • 您的意思是查找引用活动文件的所有电子表格?恐怕不会,因为它会涉及太多时间和理论上无限的运行时间
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多