getFormulas() and setFormulas() convert references to #REF

落爺英雄遲暮 提交于 2019-12-13 03:24:59

问题


I have a problem with my spreadsheet not refreshing an =IMPORTRANGE formula. I've tried all the tricks with sharing permissions and spreadsheet settings, but they don't work for me.

What I'm trying to do instead is create a simple macro that wipes the formula and re-enters it to refresh the import. When I run my macro, my formulas turns into #REF.

var ss = SpreadsheetApp.getActiveSpreadsheet();
var startingSheet = ss.getActiveSheet();

var importRange = ss.getRangeByName("MasterImport");
var importFormulas = importRange.getFormulas();
importRange.clearContent();
importRange.setFormulas(importFormulas);

My formula in named range "MasterImport" looks like this afterwards:

=IMPORTRANGE(#REF!, index(indirect(index(#REF!, match("asset_tab", #REF!, 0))),
    match(#REF!, indirect(index(#REF!, match("series_id", #REF!, 0))), 0)))

回答1:


@TheMaster's suggestion worked perfectly. Here is the final code:

var importRange = ss.getRangeByName("MasterImport");
var importFormulas = importRange.getFormulas();
importRange.clearContent();
SpreadsheetApp.flush();
importRange.setFormulas(importFormulas);


来源:https://stackoverflow.com/questions/54034452/getformulas-and-setformulas-convert-references-to-ref

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!