CopyTo方法无法使用Apps脚本捕获电子表格中的替代文本标题

时间:2019-12-18 02:28:39

标签: google-apps-script

我有一个代码,可以删除工作表并将工作表从另一个电子表格复制到另一个工作表。但是,我复制的源电子表格中包含带有“替代文字”标题的图像。当我尝试将其复制到目标文件时,没有捕获到“替代文字”标题。

关于如何解决此问题的任何想法?谢谢

function deleteAndReplaceSheet() {
  var masterConfigSheetId = 'xxxxxxx';
  var replicatedCardsFolderId = 'xxxxxxx';
  var masterSheetName = 'Mastersheet'
  var cardSheetName = "Card";
  var ss = SpreadsheetApp.openById(masterConfigSheetId);
  var masterSheetReference = ss.getSheetByName(masterSheetName);
  var replicatedCards = DriveApp.getFolderById(replicatedCardsFolderId).getFiles();

  var employeeNumbers = masterSheetReference.getRange("A2:A").getValues();
  var employeeNumbersTrunc = [];

  for(var i = 0; i < employeeNumbers.length; i++){
    if(employeeNumbers[i][0] != "")
      employeeNumbersTrunc.push("" + employeeNumbers[i][0]);
    //    Logger.log(employeeNumbersTrunc);
  }

  while (replicatedCards.hasNext()) {
    var file = replicatedCards.next();
//    Logger.log(file);

    //check if employee number is existing inside the gdrive folder
    if (employeeNumbersTrunc.indexOf(file.getName())==-1) {
      continue;

    }
    try {      
      var activeSpreadSheet = SpreadsheetApp.open(file);

      var destination = SpreadsheetApp.openById(file.getId());
      var source = SpreadsheetApp.openById('xxxxxxx');
      var sheet = source.getSheets()[0];

      var toBeDeletedSheet = activeSpreadSheet.getSheetByName('Card');

      //delete card sheetname
      activeSpreadSheet.deleteSheet(toBeDeletedSheet);
      sheet.copyTo(destination).setName('Card');
      destination.moveActiveSheet(2);

    } catch(err) {
    }
  }
}

1 个答案:

答案 0 :(得分:0)

不幸的是,您试图做的事情是不可能的。由于在单元格中插入图像仍然是Google表格中的一项新功能,因此.copyTo()方法不支持复制Alt Text Titles

我建议您在link Google Issue Tracker 上提出功能请求