Google apps script Google电子表格复制值和格式脚本问题

Google apps script Google电子表格复制值和格式脚本问题,google-apps-script,google-sheets,google-drive-api,Google Apps Script,Google Sheets,Google Drive Api,我试着搜索了很多,找到了各种各样的建议,但没有一个对我有效 我有4个单独的谷歌电子表格,由我自己所有,我们团队的各个成员更新。我想建立一个组合的电子表格,自动更新的价值观,他们改变的价值观和颜色的细胞,因为我们颜色代码的各种项目 我尝试过Importrange works,但不提供格式,还尝试了CopyValues、formatting和copyFormatting。我遇到的问题是CopyValues和Formatting只会填充第一个选项卡,而脚本的下一部分将无法工作。有人知道我的问题是什么吗

我试着搜索了很多,找到了各种各样的建议,但没有一个对我有效

我有4个单独的谷歌电子表格,由我自己所有,我们团队的各个成员更新。我想建立一个组合的电子表格,自动更新的价值观,他们改变的价值观和颜色的细胞,因为我们颜色代码的各种项目

我尝试过Importrange works,但不提供格式,还尝试了CopyValues、formatting和copyFormatting。我遇到的问题是CopyValues和Formatting只会填充第一个选项卡,而脚本的下一部分将无法工作。有人知道我的问题是什么吗?我一直在写的脚本的下面部分只是通过尝试将两张图纸合并而完成的,这是行不通的

function copyValuesandFormatting() {
     var ss = SpreadsheetApp.openById("OtherSheetURL1");
     var sourceSheet = ss.getSheetByName("Jayson");
     var ss2 = SpreadsheetApp.openById("CombinedSheetURL");  
     var targetSheet = ss2.getSheetByName("Jayson");
     var fromRange = ss.getRange("A1:Z50");
     var toRange = ss2.getRange("A1:Z50");
     var values = fromRange.getValues();
     var fontColors = fromRange.getFontColors();
     var backgrounds = fromRange.getBackgrounds();
     var fonts = fromRange.getFontFamilies();
     var fontWeights = fromRange.getFontWeights();
     var fontStyles = fromRange.getFontStyles();

    toRange.setBackgrounds(backgrounds);
    toRange.setFontColors(fontColors);
    toRange.setValues(values);
    toRange.setFontFamilies(fonts);
    toRange.setFontWeights(fontWeights);
    toRange.setFontStyles(fontStyles);

} 

function copyValuesandFormatting() {
    var ss3 = SpreadsheetApp.openById("OtherSheetURL2");
    var sourceSheet = ss3.getSheetByName("Robin");
    var ss4 = SpreadsheetApp.openById("CombinedSheetURL");
    var targetSheet = ss4.getSheetByName("Robin");

    var fromRange = ss3.getRange("A1:Z50");
    var toRange = ss4.getRange("A1:Z50");
    var values = fromRange.getValues();
    var fontColors = fromRange.getFontColors();
    var backgrounds = fromRange.getBackgrounds();
    var fonts = fromRange.getFontFamilies();
    var fontWeights = fromRange.getFontWeights();
    var fontStyles = fromRange.getFontStyles();

    toRange.setBackgrounds(backgrounds);
    toRange.setFontColors(fontColors);
    toRange.setValues(values);
    toRange.setFontFamilies(fonts);
    toRange.setFontWeights(fontWeights);
    toRange.setFontStyles(fontStyles);


}

今天早上,我似乎可以在每张原始表格中使用CopyTo使其正常工作

function copyTo( {
  //gets and formats data ranges, to and from sheets.
   var ss = SpreadsheetApp.getActiveSpreadsheet(); 
   var target = SpreadsheetApp.openById("DestinationURL");
   var source_sheet = ss.getSheetByName("Jayson");
   var target_sheet = target.getSheetByName("Jayson");
   var source_range = source_sheet.getRange("A1:Z100");
   var target_range = target_sheet.getRange("A1:Z100");
   //gets then writes values defined in setup
   var values = source_range.getValues(); 
   var values = source_range.getValues();
   var fontColors = source_range.getFontColors();
   var backgrounds = source_range.getBackgrounds();
   var fonts = source_range.getFontFamilies();
   var fontWeights = source_range.getFontWeights();
   var fontStyles = source_range.getFontStyles();
   target_range.setValues(values);
   target_range.setBackgrounds(backgrounds);
   target_range.setFontColors(fontColors);
   target_range.setValues(values);
   target_range.setFontFamilies(fonts);
   target_range.setFontWeights(fontWeights);
   target_range.setFontStyles(fontStyles);
   //for checking last row with data in cell and formatting range
   var lastRow = source_sheet.getLastRow();