I want to substitute the ImportRange function that I have on a gsheet with apps script. Therefore, I am using methods such as getValues()
and setValues()
. However when I run the script there are rows of the first column of the range that get unformatted. The original data format is string but in some rows I get kind of dates format (see the link with a screenshot). For example, in row 67 I should get there a link like http://admin.(.....)/73100.
Screenshot of the data returned by the script
function paste_main_query() {
var ss=SpreadsheetApp.openById("(ID)");
var destination = ss.getSheetByName("STM_query");
var import_range_aux= destination.getRange('A2:A').getValues();
var numRows = import_range_aux.filter(String).length;
var import_range = destination.getRange('A2:G'+numRows).getDisplayValues()
var sorted_1 = ArrayLib.sort(import_range,6,false) // ascending column 4
var sorted_2 = ArrayLib.sort(sorted_1,3,true) // ascending column 4
var sorted_3 = ArrayLib.sort(sorted_2,0,false) // ascending column 4
var destination = ss.getSheetByName("import_range_aux");
destination.getRange('A2:G').clearContent();
destination.getRange(2,1,sorted_3.length, sorted_3[0].length).setValues(sorted_3);
}
Notes:
- I have already tried both methods:
getValues()
andgetDisplayValues()
- I have already used the
importrange
variable on the last row of the code and I got the same errors, so the problem is not from sorting the data with theArrayLib
library
Do you have any idea of what I can be doing wrong here? Any tip is more than welcome.
Format > Number > Select your formatting
- I hope this is helpful to you