Using the script below, numbers formatted as text are being changed to time format, even though I have Column E2:E in Logged_Data sheet formatted as "Plain text". What is the reason for this? And what can I do to fix it?
In Data_Input!D8, the cell is formatted as "Plain text":
However, when it appears on the Logged_Data sheet, it is formatted as time:
Here is the script I am using:
function transposeAndAppend() {
let ss = SpreadsheetApp.getActiveSpreadsheet();
let shtIn = ss.getSheetByName("Data_Input");
let shtOut = ss.getSheetByName("Logged_Data");
let responses = shtIn.getRange("D4:D11").getValues();
//responses is a 2d array that looks like this [[a],[b],[c]]
//first transpose it
let transResp = responses[0].map((resp,i)=>responses.map(r => r[i]))
//we now have [[a,b,c]]
shtOut.appendRow(transResp.flat())
//Clear the 'form'
shtIn.getRange("D4:D11").clearContent();
}
According to Hyde at Google Support, https://support.google.com/docs/thread/99094988/can-you-format-the-data-when-doing-appendrow?hl=en, this should not be happening.
I believe your goal is as follows.
I would like to propose using the copyTo method of Class Range. The modified script is as follows.
function transposeAndAppend() {
let ss = SpreadsheetApp.getActiveSpreadsheet();
let shtIn = ss.getSheetByName("Data_Input");
let shtOut = ss.getSheetByName("Logged_Data");
// I modified the below script.
const srcRange = shtIn.getRange("D4:D11");
const dstRange = shtOut.getRange(shtOut.getLastRow() + 1, 1);
srcRange.copyTo(dstRange, SpreadsheetApp.CopyPasteType.PASTE_VALUES, true);
}