Google apps script 仅将值从一个google工作表复制到另一个工作表的脚本不起作用
我试图将值仅从google工作表中的特定选项卡复制到另一个google工作表,然后删除该选项卡。基本上,我想将一些数据从一张表归档到下一张表。需要删除该工作表,以便在下一周将同一工作表复制到存档工作表中 我尝试过各种不同的方法,但都不奏效 代码块具体如下所示:Google apps script 仅将值从一个google工作表复制到另一个工作表的脚本不起作用,google-apps-script,Google Apps Script,我试图将值仅从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 au
//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);
}
这基本上就是您的函数的概括:
function copyTo() {
var ss = SpreadsheetApp.getActive();
var source1 = SpreadsheetApp.openById('1PDlQc3bHR4Wa2j72K01HiWCtrto36AXDhVf1d9Ajtpg');//same id
var sheet1 = source1.getSheets()[2];
var dest1 = SpreadsheetApp.openById('1PDlQc3bHR4Wa2j72K01HiWCtrto36AXDhVf1d9Ajtpg');//same id
sheet1.copyTo(dest1);//So this is a copy of third sheet from left
var thisDatePart =Utilities.formatDate(new Date(), Session.getScriptTimeZone(), "MMM dd")
var second = ss.getSheetByName("Copy of WeeklyInventoryTemplate");
second.setName(thisDatePart);
var source2 = ss.getSheets()[16].getRange(6,2,315,1);
var dest2 = ss.getSheetByName(thisDatePart).getRange(6,5,315,1)
source2.copyTo(dest2);//copy data from 17th sheet from left to sheet named month day i.e. theDatePart
}
function copyInfo() {
var source = SpreadsheetApp.openById('1PDlQc3bHR4Wa2j72K01HiWCtrto36AXDhVf1d9Ajtpg');//different ids
var sheet = source.getSheets()[15];//16th sheet from left
var destination = SpreadsheetApp.openById('1MGN3UtOgVg2N6V4cWGqCIpFIITZZQV0OtAJNRevM09o');//different ids
var valuesonly = SpreadsheetApp.CopyPasteType.PASTE_VALUES;
sheet.copyTo(destination,valuesonly,true);//This copies the 16th sheet from left to another spreadsheet.
}
这里有两行:
var first = SpreadsheetApp.setActiveSheet(ss.getSheetByName("Copy of WeeklyInventoryTemplate"));
var second = ss.getSheetByName("Copy of WeeklyInventoryTemplate");
但是你没有用“first”做任何事情,所以我想知道你是否在尝试获取模板的副本
您还有一个名为“电子表格”的函数参数,但从未在函数体中使用过它
我认为使用这样的引用有点危险:source.getSheets()[15]因为我相信用户可以通过移动标签来改变它们
我没有看到您在哪里删除了选项卡/工作表。提供不起作用不是问题描述。