0

I need to change the NumberFormat for all the values into a specific column with app script. Here is an extract of my code :

var range = ss.getRange(2,2,ss.getMaxRows(),1).getValues();
range.setNumberFormat("0");

The execution displays the following error : "TypeError: range.setNumberFormat is not a function" but I do not understand why.

For your information, when I log my range with :

Logger.log(range)

Here is the result :

[[2.0222117E7], [2.0222004E7], [2.0222004E7], [2.0222003E7], [2.0222002E7], [2.0222001E7], [2.0211004E7], [2.0211003E7], [2.0211002E7], [2.0211001E7], [2.0200004E7], [2.0200003E7], [2.0200002E7], [2.0200001E7], [2.0199001E7],...

Many thanks

TheMaster
  • 45,448
  • 6
  • 62
  • 85
Sébastien
  • 11
  • 1

1 Answers1

3

Because the variable range is not a member of the real class range. It's a two dimensional array Array[][]. Only real Range objects have methods like setNumberFormat.

const range =/*This is a range*/ ss.getRange(2,2,ss.getMaxRows(),1);
const values = /*This is not a range*/range.getValues();
range.setNumberFormat("0");

Related: What does the range method getValues() return and setValues() accept?

TheMaster
  • 45,448
  • 6
  • 62
  • 85