I need some help after battling with this issue. & years ago this guy asked this and the script in the answer is wicked, I need the inverse, I need the words and not the formulas. Who can I do that? I'm providing a screenshoot of the Google Spreadsheet and the file link as well. Thanks in advanced:
Thanks a lot lovely people!
Jose Baires.
========Old post:
How can I convert all cells from formulas to plain text so I can export them as CSV?Asked 7 years, 2 months agoModified 6 years, 2 months agoViewed 4k times4
I have around 12 sheets in a Google Spreadsheets document where I have a bunch of formulas. I'd like to do one of two things:
I would love to just export these as CSVs. I don't want the values though, I want the actual formulas. I.e. instead of the cell value being 3, I would like it to be =B2+B4. I don't mind manually downloading each.
If that's not possible, is there some way to convert all the the formula cells to the formula itself?
I know that I can just put quotes around the formulas and they will become text strings which I can then export to CSV. The issue is, that's a lot of cells ... and I don't want to have to do that for all the cells.
Can you folks help me out with this?
google-sheetsgoogle-apps-scriptShareEditFollowedited Aug 20, 2017 at 17:37pnuts's user avatarpnuts17.4k55 gold badges5252 silver badges103103 bronze badgesasked Aug 6, 2016 at 15:57Ringo Blancke's user avatarRingo Blancke32311 gold badge33 silver badges55 bronze badgesAdd a comment1 AnswerSorted by:
Highest score (default)2
The following script implements your second approach: convert all formula cells to the text displaying the formula. It does so in all sheets in the current spreadsheet.
The idea is simple: get all values (getValues) and formulas (getFormulas). If a cell contains a formula, then the new value is the formula text prepended by the apostrophe ' (which isn't displayed; it's just an indicator that the cell content should be treated as plain text).
After exporting the sheets as CSV (one by one, using the menu), you can restore the original state of the spreadsheet either by using revision history, or by running the same script again. (If the script runs again, a cell having text content =A1+1 will again become a formula =A1+1)
function formulasAsText() {var sheets = SpreadsheetApp.getActiveSpreadsheet().getSheets();for (var k = 0; k < sheets.length; k++) {var range = sheets[k].getDataRange();var values = range.getValues();var formulas = range.getFormulas();for (var i = 0; i < values.length; i++) {for (var j = 0; j < values[0].length; j++) {values[i][j] = formulas[i][j] ? "'" + formulas[i][j] : values[i][j];}}range.setValues(values);}}ShareEditFollowanswered Aug 6, 2016 at 18:56user79865Thanks so much for this! Works great. Accepting this answer now. I have a follow up question. Turns out that some of the cells are actually not formulas ... but just links. I have no idea how to turn a link into a hyperlink formula. Here's the question if you happen to have a few minutes / know what to do. Thanks again! webapps.stackexchange.com/questions/97285/…–Ringo BlanckeAug 6, 2016 at 19:24
