【问题标题】:google sheets copy formatting from active sheet to every other sheet谷歌表格将格式从活动表格复制到其他所有表格
【发布时间】:2021-01-16 21:11:19
【问题描述】:

我真的需要你的帮助。 2 天后,我仍然处于“零”状态。

我需要一个将所有格式从活动工作表复制到其他所有工作表的脚本。 如果有条件格式、交替颜色和数据验证也很好。 我认为这并不难,但我在剧本写作方面确实是新手。

这是表格:

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
  }
})
}

我能够弄清楚并编写一些功能:清除所有工作表上的格式,格式化所有工作表上的行标题,显示工作表列表,但这对我来说太难了。 即使我尝试先使用宏记录器对其进行建模。

如果您能帮我解决这个问题,我将不胜感激。

【问题讨论】:

    标签: google-apps-script google-sheets


    【解决方案1】:

    我想通了:

    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
      }
    })
    }
    

    参考

    【讨论】:

      【解决方案2】:

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-04-25
        • 2017-03-11
        • 1970-01-01
        • 2020-10-29
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多