S
S
serw_802020-05-14 09:57:53
Google Apps Script
serw_80, 2020-05-14 09:57:53

How to automatically create a copy of a spreadsheet sheet?

Good afternoon!

Please help me write a script for google sheets.

The bottom line is that there is an initial sheet that is filled out daily and printed out.
It is necessary to make it so that when filling in the first (template) sheet of the table, a separate copy sheet is displayed by clicking the button.
Thus, 30-31 sheets with data should be created in the new file per month.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Ivanov, 2020-05-14
@serw_80

You will need Google Apps Script to run the program from the Tables menu.
Create a menu

function onOpen() {
  SpreadsheetApp.getUi()
    .createMenu('Reset sheet')
    .addItem('Make a copy before reset', 'userActionMakeCopyBeforeReset')
    .addToUi();
}

User action
function userActionMakeCopyBeforeReset() {
  const book = SpreadsheetApp.getActive();
  const sheet = book.getActiveSheet();
  makeCopyBeforeReset_(sheet, book);
}

Copying and Resetting a Master Sheet
function makeCopyBeforeReset_(sheet, book) {
  const copy = sheet.copyTo(book);
  const rangesAddressesList = ['B5', 'B7', 'B9', 'B11'];
  resetByRangesList_(sheet, rangesAddressesList);
  return copy;
}

Basic data reset method
function resetByRangesList_(sheet, rangesAddressesList) {
  sheet.getRangeList(rangesAddressesList).clearContent();
}

Having collected all this, you should get a program like in the video https://twitter.com/i/status/1260851838942957574
Example in the Table https://docs.google.com/spreadsheets/d/1g8cCxofljF...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question