【发布时间】:2022-04-12 00:23:05
【问题描述】:
我喜欢复制/粘贴所有旧工作表作为值以节省资源,但我不想删除公式,因为我依赖它们在将来重新创建它们(有些非常复杂)。我认为一个不错的选择是将每个公式复制到其单元格的注释中,然后再粘贴为值,所以我认为我可以编写一个脚本来执行此操作,最好是在整个工作表中。我承认我去这里时正在谷歌搜索,但我在正确的轨道上吗?我是否有正确的变量来开始处理循环?
function CopyFormulaToNote() {
/* I dont' want to get just the active sheet but all of them
look into how to do that */
var ss=SpreadsheetApp.getActive().getActiveSheet();
var lr=ss.getLastRow();
var lc=ss.getLastColumn();
var range=ss.getRange(1,1,lr,lc);
/* Find the first formula in the entire spreadsheet
I doubt it will just find all formulas per se without specifying that a formula begins with =
although there is a getFormula function...
and if I do have to specify that I think what I have below says to look for = as the first character */
var search=range.createTextFinder().matchFormulaText("^[=]"); //search for formula ie first character =
var result=search.getCurrentMatch(); //I *think* this would get the 1st result
var cell=result.getCell(row, column); //get the cell range of the result
var note=cell.setNote(note); //create a cell note for that cell
/* and now create a loop to do it everywhere that includes */
result.CopyTo(note); //copy the result into the note
}
【问题讨论】:
-
@Tanaike 辉煌!我想可能有更简单的方法。非常感谢您抽出宝贵的时间。
-
感谢您的回复。很高兴您的问题得到解决。
标签: google-apps-script google-sheets