Google Script – Plain Text

Google Sheets often thinks it’s smarter than you. That’s helpful at times and irritating at other times.1

The Google Form to Sheets path is one place where that can come up repeatedly and in ways that are hard to see. For instance, if you use the Time entry on forms, Google Sheets tries to coerce it into a date structure while leaving you seeing just the time in the sheets view. That leads to weird and unpredictable stuff if you’re trying to use Google Scripts to interact with that cell data based on what you see.

For instance, this is data from the time entry field as seen on the sheet side. Note the two places you might expect to see truth.

Google Sheets lying to me about the field data I guess.

Now if we get that same data via Google Script . . . Cell data that you’d expect to just be that time element returns as Sat Dec 30 1899. The time is right though.
Cell data that should be just time returns via Google Script as Sat Dec 30 1899. The time is right though.

If you manually change the format of that column to plain text things work . . . but it gets re-set on all subsequent submissions.

My solution so far has been the following Google Script set to fire on every new form submission. In my case, I’m changing the format of the latest entry in the spreadsheet in columns F and G to plain text.

function plainText (){
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheetByName('Form Responses 1');
  var lastRow = sheet.getLastRow();
  var range = sheet.getRange('f'+ lastRow +':g'+lastRow);
  range.setNumberFormat('@STRING@'); // found this format https://stackoverflow.com/questions/13758913/format-a-google-sheets-cell-in-plaintext-via-apps-script  
}

1 Mostly, I find it irritating.

Comments on this post

No comments.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Trackbacks and Pingbacks on this post

No trackbacks.

TrackBack URL