Search code examples
google-apps-scriptgoogle-sheets

Reset Column and Row sizes to default


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?


Solution

  • I think, this plan should work:

    1. add new sheet
    2. define defaults: getColumnWidth(columnPosition) and getRowHeight(rowPosition)
    3. delete new sheet
    4. set defaults: setColumnWidth(columnPosition, width) and setRowHeight(rowPosition, height)

    For more info look at Class Sheet documentation