簡體   English   中英

谷歌表格將格式從活動表格復制到其他所有表格

[英]google sheets copy formatting from active sheet to every other sheet

我真的需要你的幫助。 2天后,我仍然在“零”上。

我需要一個腳本,將所有格式從活動工作表復制到其他所有工作表。 最好有條件格式,交替 colors 和數據驗證。 我認為這並不難,但我在劇本寫作方面真的很新。

這是單子:

https://docs.google.com/spreadsheets/d/1mOkm_r4rngPXTkIerSQJKxRih31sM7XoZCZVnoHUc5M/edit?usp=sharing

到目前為止的代碼:

enter function copyFormatting(){
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
var copyTo = ss.getSheetByName('agent2');
var range = copyTo.getRange(1, 1, copyTo.getMaxColumns(), copyTo.getMaxRows());
sheet.getBandings()[0].copyTo(copyTo.getRange(1,1)),SpreadsheetApp.CopyPasteType.PASTE_FORMAT, false);
}

function allcopyFormatting() {
var spreadsheet = SpreadsheetApp.getActive();
var allSheets = spreadsheet.getSheets();
allSheets.forEach(function(sheet){
  if(sheet.getSheetName() !== "detroit"){ // if you dont want to use the formatting on this sheet
sheet.activate();
copyFormatting(); // the function what yo like to run
  }
})
}

我能夠弄清楚並編寫一些功能:清除所有工作表上的格式,格式化所有工作表上的行標題,顯示工作表列表,但這對我來說太難了。 即使我先用宏記錄器嘗試 model 它。

如果您能幫助我解決這個問題,我將不勝感激。

我能夠弄清楚:

function allcopyFormatting() {
var spreadsheet = SpreadsheetApp.getActive();
var allSheets = spreadsheet.getSheets();
var sampleSheet = spreadsheet.getActiveSheet();  // from the spreadsheet select the active sheet
var maxRow =sampleSheet.getMaxRows();
var maxCol =sampleSheet.getMaxColumns();
var sampleRange = sampleSheet.getRange(1,1,maxRow,maxCol);
allSheets.forEach(function(sheet){
  if(sheet.getSheetName() !== "detroit"){ // if you dont want to use the formatting on this sheet
sheet.activate();
var targetSheet = spreadsheet.getActiveSheet();  // from the spreadsheet select the active sheet
var targetRange = targetSheet.getRange(1,1);
sampleRange.copyTo(targetRange, {formatOnly:true})  // it copies the formatting
  }
})
}

參考

嘗試insertSheet(options) ,如果不起作用,請嘗試copyTo(destination, options)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM