Reset Column and Row sizes to default

Viewed 6071

I am building a script (accessed through a custom menu item) that will also include some styling. Things like setting background colours, changing the width of columns, the heights of rows and inserting a lot of content.

Now I would like to implement a 'reset'-function: set all cells back to what a default, empty Google Sheet looks like, including all content. I found the clear() function in the documentation, but this only removes the content while keeping the width/height the same.

The question: How can i reset a modified spreadsheet (content, width/height, styling) back to looking like a default Google Sheet spreadsheet?

3 Answers

There is now functionality for this.

Right-click on the column and select Resize the column.

Then set the width to 100px as is the default.

I needed the same thing, so here's the code, based on Max Makhrov's idea:

let ss = SpreadsheetApp.getActiveSpreadsheet();
let sheet = ss.getSheets()[0]; // sheet you want to change
let tempSheet = ss.insertSheet((new Date()).toLocaleTimeString()); // temp sheet

sheet.setColumnWidths(1, sheet.getMaxColumns(), tempSheet.getColumnWidth(1));
sheet.setRowHeights(1, sheet.getMaxRows(), tempSheet.getRowHeight(1));
ss.deleteSheet(testSheet);
Related