Recalculate references after copying to Google Spreadsheet


I have the problem of lost references after a copy in Google Spreadsheet, which was solved in this post by the "search and replace" of "=". But is there a trick in recalculating in Google Apps Script instead of Google Sheet? In fact, it's the same problem, but the thing is, I copy the file into a Google Apps script that plays a lot of times. Therefore, I would like to recalculate at the end of the same script.

I've already tried two things in GAS: I just made a getFormulas () and setFormulas () for that leaf for that leaf, but for the cells without a formula, only getFormula () returns empty text and overrides setFormula () it with the empty string, so I lose my text.

After that, I made a simple double loop that flips through all my cells and where I manually test for the getFormula () return, and I set the setFormula () only if the string is not empty. This works fine, but since I have to do a getRange () for every single cell, that's very, very, very long (I have thousands of cells, it takes a few minutes). Seeing how fast the Find & Replace guide runs is frustrating …

I also tried to record a macro that performs manual search and replace to see what code is being recorded, but the macro remains empty …

Do you know how to perform "Find by Replace" in Google Apps Script (or any other workaround)?

Many Thanks