Я пытаюсь скопировать значения только с определенной вкладки в листе Google на другой лист Google, а затем удалить вкладку. По сути, я хочу заархивировать некоторые данные с одного листа на другой. Лист необходимо удалить, чтобы на следующей неделе этот же лист # был скопирован на лист архива.
Я пробовал разные методы, и ни один из них не сработал.
Блок кода, в частности, таков:
//Archive the sheet from two weeks ago. This part is still being worked on. Once this is figured out, we can have it automate.
//Something in the final copyTo function is broken.
function copyInfo() {
var source = SpreadsheetApp.openById('1PDlQc3bHR4Wa2j72K01HiWCtrto36AXDhVf1d9Ajtpg');
var sheet = source.getSheets()[15];
var destination = SpreadsheetApp.openById('1MGN3UtOgVg2N6V4cWGqCIpFIITZZQV0OtAJNRevM09o');
var valuesonly = SpreadsheetApp.CopyPasteType.PASTE_VALUES;
sheet.copyTo(destination, valuesonly, true);
}
Однако вот полный блок кода, чтобы вы могли видеть, что я пытаюсь сделать:
// popup menu on open
function onOpen() {
Browser.msgBox('Black tabs = data transferred but need more data. Changes: Adhesive vs nonadhesive tabs were removed and in their place, Solvent and Latex tabs were created to follow the flow of the inventory template sheet. IMPORTANT: Please notify Carrie if you add lines to the sheets so she can make sure data is correctly allocated on the weekly inventory template. Thank you!', Browser.Buttons.OK);
}
//Custom menu located on the top menu bar called "Custom Menu"
function onOpen() {
var ui = SpreadsheetApp.getUi();
ui.createMenu('Custom Menu').addItem('Copy Weekly Inventory', 'copyTo').addSeparator().addItem('Archive', 'copyInfo').addToUi();
}
//Copy the 3rd sheet from the left to a new sheet, and name that sheet with today's date.
//Copy the previous week's unopened data to new sheet.
function copyTo(spreadsheet) {
var source = SpreadsheetApp.openById('1PDlQc3bHR4Wa2j72K01HiWCtrto36AXDhVf1d9Ajtpg');
var sheet = source.getSheets()[2];
var destination = SpreadsheetApp.openById('1PDlQc3bHR4Wa2j72K01HiWCtrto36AXDhVf1d9Ajtpg');
sheet.copyTo(destination);
var thisDate = new Date();
Logger.log(thisDate);
var month = new Array();
month[0] = "Jan";
month[1] = "Feb";
month[2] = "Mar";
month[3] = "Apr";
month[4] = "May";
month[5] = "Jun";
month[6] = "Jul";
month[7] = "Aug";
month[8] = "Sep";
month[9] = "Oct";
month[10] = "Nov";
month[11] = "Dec";
var mo = month[thisDate.getMonth()];
Logger.log(mo);
var day = thisDate.getDate();
Logger.log(day);
var thisDatePart = mo + ' ' + day;
Logger.log(thisDatePart);
var ss = SpreadsheetApp.getActiveSpreadsheet();
var first = SpreadsheetApp.setActiveSheet(ss.getSheetByName("Copy of WeeklyInventoryTemplate"));
var second = ss.getSheetByName("Copy of WeeklyInventoryTemplate");
second.setName(thisDatePart);
var copyInfo = SpreadsheetApp.getActiveSpreadsheet().getSheets()[16];
var source = copyInfo.getRange(6, 2, 315, 1)
var destination = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(thisDatePart).getRange(6, 5, 315, 1)
source.copyTo(destination);
}
//Archive the sheet from two weeks ago. This part is still being worked on. Once this is figured out, we can have it automate.
//Something in the final copyTo function is broken.
function copyInfo() {
var source = SpreadsheetApp.openById('1PDlQc3bHR4Wa2j72K01HiWCtrto36AXDhVf1d9Ajtpg');
var sheet = source.getSheets()[15];
var destination = SpreadsheetApp.openById('1MGN3UtOgVg2N6V4cWGqCIpFIITZZQV0OtAJNRevM09o');
var valuesonly = SpreadsheetApp.CopyPasteType.PASTE_VALUES;
sheet.copyTo(destination, valuesonly, true);
}