Get Column to Display Month Name Google App Script

How can I set the column to display the month name instead of the entire date using a script?

The function can be done manually by selecting Format>Number>August

from the menu, but I want to do it in code.

This is what I've tried, but can't seem to find what I should put as the formatting condition:

function myFunction() {
  var spr = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = spr.getSheets()[0];
  var column = sheet.getRange("A:A");
  column.setNumberFormats("Month"); // I'm pretty sure it not supposed to be "Month" here, so what is it supposed to be?
}

      

Lightening; I want to change the whole column: 01/01/2015

to show January

.

The error message I get above the code is "Cannot find method setNumberFormats (string)" and it is the same if I change "Month"

to "L"

or "MM"

.

+3


source to share


1 answer


Lots of typos in your script ... (be careful when writing code and use autocomplete to check spelling: control + SPACE)

the code looks like this:



function myFunction() {
  var spr = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = spr.getSheets()[0];
  var column = sheet.getRange("A:A");
  column.setNumberFormat("MMMM"); // MMM for abbreviated month, MM for month number
}

      

+1


source







All Articles