Range.copyTo(DestinationRange, .PASTE_NORMAL, false) 复制失败

Range.copyTo(DestinationRange, .PASTE_NORMAL, false) failing to copy

如果我未能描述我面临的问题和/或我偶然发现它的背景,我应该先道歉。如果有任何其他信息可以帮助您了解正在发生的事情,请告诉我。

上下文: 我在一个电子表格中有两张纸:"Checklist",它应该作为一种形式工作,"Edit Checklist",顾名思义,它将用于编辑前者的格式。这个想法是,一旦用户完成编辑,宏就会通过简单地将新版本复制到旧版本来替换以前的形式。

问题: 通过脚本使用 Range.copyTo() 函数不会复制整个新表单,会丢失一整列,尤其是格式和合并范围。请找到以下屏幕截图

代码

/**
 *   Updates the checklist form after edditing.
 */
function update_checklist(){

  // First we clean whatever used to be the checklis
  del_checklist_sections();

  // Now we gather the new checklist into a range
  new_checklist = get_edit_checklist_form_range();

  // We now have to make room for the new list on the Checklist Sheet
  b_row = spreadsheet.getRangeByName("Checklist!"+NAMED_RANGES.form_start).getRow();
  f_form.insertRowsAfter(b_row, new_checklist.getNumRows());

  //new_checklist.copyFormatToRange(f_form, 1, new_checklist.getLastColumn(), b_row+1, b_row+1+new_checklist.getNumRows());

  new_checklist.copyTo(get_checklist_form_range(), SpreadsheetApp.CopyPasteType.PASTE_NORMAL, false);
  //new_checklist.copyTo(get_checklist_form_range(), SpreadsheetApp.CopyPasteType.PASTE_VALUES, false);

}

/**
 *   Correctly grabs the sections and tasks range in the checklist sheet. 
 *
 * The correct range doesn't include the first and last rows of the named range. 
 *
 * @return {Range} the corresponding range.
 */
function get_checklist_form_range(){

  full_range = spreadsheet.getRangeByName("Checklist!"+NAMED_RANGES.full_form);
  if (full_range.getNumRows() > 2){

    // We are adding one so we won't consider the initial row in the range, and subtracting to so we won't consider the first and last.
    return f_form.getRange(full_range.getRow()+1, full_range.getColumn(), full_range.getNumRows() - 2);
  }else{
    return 0
  }

}

function get_edit_checklist_form_range(){

  full_range = spreadsheet.getRangeByName("Edit Checklist!"+NAMED_RANGES.full_form)
  // We are adding one so we won't consider the initial row in the range, and subtracting to so we won't consider the first and last.
  //  return f_form.getRange(full_range.getRow()+1, full_range.getColumn(), full_range.getNumRows() - 2)
  return e_form.getRange(full_range.getRow()+1, full_range.getColumn(), full_range.getNumRows() - 2);

}

注意:为了更容易找到范围,我使用命名范围来指定部分工作表。

更新:

  1. 我尝试录制一个宏来执行复制和粘贴任务,使用生成的代码效果很好。我将我的代码与自动生成的代码进行了比较,唯一的区别是范围的编写方式,但最终它们应该是相同的。
  2. 我尝试先粘贴格式,然后再粘贴值;没用。

我花了一段时间才回到这个项目,但我们开始吧:

问题在于我是如何获取射程的。原来我没有选择所有我想复制和粘贴的数据。