I have used a Script posted here in a large Google Spreadsheet, to replace a String with a Number.
It works great, but the problem is, the date gets turned into a String.
I believe that the problem is the method toString()
, but I couldn't find any alternative to make the code work.
=> Does anyone have an idea to avoid this problem?
Script
function runReplaceInSheet(){
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet3");
// get the current data range values as an array
// Fewer calls to access the sheet -> lower overhead
var values = sheet.getDataRange().getValues();
// Replace
replaceInSheet(values, 'datateam', '42007860');
// Write all updated values to the sheet, at once
sheet.getDataRange().setValues(values);
}
function replaceInSheet(values, to_replace, replace_with) {
//loop over the rows in the array
for(var row in values){
//use Array.map to execute a replace call on each of the cells in the row.
var replaced_values = values[row].map(function(original_value) {
return original_value.toString().replace(to_replace,replace_with);
});
//replace the original row values with the replaced values
values[row] = replaced_values;
}
}
Before
After