我有30张单独的工作表,需要将它们合并到具有多个标签的工作表中。我可以使用以下脚本来执行此操作,但是每次都会创建一个新的工作表。当更新30个单独的工作表中的一个或全部时,我只希望此脚本更新或重写以前创建的“主工作表”。
function mergeSheets()
{
/* Retrieve the desired folder */
var myFolder = DriveApp.getFoldersByName("Email Groups").next();
/* Get all spreadsheets that resided on that folder */
var spreadSheets = myFolder.getFilesByType("application/vnd.google-apps.spreadsheet");
/* Create the new spreadsheet that you store other sheets */
var newSpreadSheet = SpreadsheetApp.create("All Districts Email");
/* Iterate over the spreadsheets over the folder */
while(spreadSheets.hasNext()) {
var sheet = spreadSheets.next();
/* Open the spreadsheet */
var spreadSheet = SpreadsheetApp.openById(sheet.getId());
/* Get all its sheets */
for(var y in spreadSheet.getSheets()) {
/* Copy the sheet to the new merged Spread Sheet */
spreadSheet.getSheets()[y].copyTo(newSpreadSheet);
}
}
}
我正在寻找一张包含每个地区的标签的工作表。这将使我可以与一张单独更新的所有信息共享一个母版纸。
答案 0 :(得分:0)
={IMPORTRANGE("ID1", "Sheet1!A1:B10"),
IMPORTRANGE("ID1", "Sheet2!A1:B10"),
IMPORTRANGE("ID1", "Sheet3!A1:B10"),
IMPORTRANGE("ID2", "Sheet1!A1:B10"),
IMPORTRANGE("ID2", "Sheet2!A1:B10"),
IMPORTRANGE("ID3", "Sheet8!A1:B10"),
IMPORTRANGE("ID4", "Sheet7!A1:B10"),
IMPORTRANGE("ID4", "Sheet9!A1:B10")}
等...
还请注意,每个具有唯一ID的IMPORTRANGE
公式都必须先分别粘贴到允许访问