10

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.

3 Answers 3

9

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();
2

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

0
function clearFormatting() {
  var activeSheet = SpreadsheetApp.getActiveSheet();

  activeSheet.clear({
    formatOnly: true,
    contentsOnly: false
  });
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.