art crafters
art crafters

Reputation: 1

Size Up/Down Maco for Google sheets

Since Google Sheets does not have a font size up/down keyboard shortcut I decided to try and make my own. I used the Macro feature and created two separate macros, then opened the script but it didn't work.

I've had a look through the documentation but couldn't find anything.

Here's where I am with my code:

/** @OnlyCurrentDoc */

function Sizeup() {
   var spreadsheet = SpreadsheetApp.getActive();
   var size = getFontSize();//getFontSize is not standalone
   spreadsheet.getActiveRangeList().setFontSize(size+1);//getActiveRangeList() returns an array of Ranges not a Range so no setFontSize() method there
};

function Sizedown() {
   var spreadsheet = SpreadsheetApp.getActive();
   var size = getFontSize();
   spreadsheet.getActiveRangeList().setFontSize(size-1);
};

Upvotes: 0

Views: 23

Answers (1)

Cooper
Cooper

Reputation: 64100

Maybe something like this:

function Sizeup() {
   const ss=SpreadsheetApp.getActive();
   const rA=ss.getActiveRangeList().getRanges();
   rA.forEach(function(rg,i){
     rg.setFontSize(rg.getFontSize()+1);   
   });
};

function Sizeup() {
   const ss=SpreadsheetApp.getActive();
   const rA=ss.getActiveRangeList().getRanges();
   rA.forEach(function(rg,i){
     let s=rg.getFontSize()-1;
     rg.setFontSize((s>0)?s:s+1);   
   });
}

Upvotes: 1

Related Questions