Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to "Clear Format" in Google Sheets via Apps Script

In my Google Sheet, I currently remove formatting by manually going to Format > Clear Formatting.

How can I programmatically (via Apps Script) clear any/all formatting that may exist in a Google Sheet's row(s) and/or column(s)?

Clarification: I am aware of the Text Class that has formatting functions (eg. setForegroundColor(), setItalic(), setTextAlignment(), etc), but I'm not aware of any single function that will do the same thing as the Format > Clear Formatting function that is available in the Main Menu.

like image 677
Jed Avatar asked May 03 '16 17:05

Jed


2 Answers

There is a clearFormats() method in the Sheet Class.
https://developers.google.com/apps-script/reference/spreadsheet/sheet#clearformats

Example from the docs:

// This example assumes there is a sheet named "first"
 var ss = SpreadsheetApp.getActiveSpreadsheet();
 var first = ss.getSheetByName("first");
 first.clearFormats();
like image 114
Spencer Easton Avatar answered Nov 14 '22 15:11

Spencer Easton


The clearFormat() function I am looking for is in the Range Class.

like image 24
Jed Avatar answered Nov 14 '22 13:11

Jed