问题
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