Reputation: 711
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?
Upvotes: 7
Views: 8288
Reputation: 1
I found this useful, in case somebody else needs this there is a little mistake in the last line of the code. Here is a working version:
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(tempSheet);
Upvotes: 0
Reputation: 3401
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);
Upvotes: 0
Reputation: 3628
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.
Upvotes: 5
Reputation: 18707
I think, this plan should work:
getColumnWidth(columnPosition)
and getRowHeight(rowPosition)
setColumnWidth(columnPosition, width)
and setRowHeight(rowPosition, height)
For more info look at Class Sheet documentation
Upvotes: 1