0

在上周的 IO 之后,我在文档的 UI 中添加了一个选项,可以将会议从昨天的会议记录表迁移到今天的会议记录表。

当我在脚本编辑器中调试或运行时,脚本运行良好,但是,当我从 UI 运行时,我收到一条错误消息,提示函数遇到错误。发生错误,我们无法保存您的更改。

错误的屏幕截图

下面是我的代码:

function onOpen() {
  var UI = DocumentApp.getUi();
  UI.createMenu("StandUp").addItem("Migrate Yesterday", DoMigrate).addToUi();  
}

function DoMigrate(){

var dater =new Date();  
var weekday=new Array(7);
weekday[0]="Sunday";
weekday[1]="Monday";
weekday[2]="Tuesday";
weekday[3]="Wednesday";
weekday[4]="Thursday";
weekday[5]="Friday";
weekday[6]="Saturday";

var month=new Array(12);
month[0]="January";
month[1]="Febuary";
month[2]="March";
month[3]="April";
month[4]="May";
month[5]="June";
month[6]="July";
month[7]="August";
month[8]="Sept";
month[9]="Oct";
month[10]="Nov";
month[11]="Dec";

var dayOfWeek = weekday[dater.getDay()];
var theMonth = month[dater.getMonth()];
  var paragraph = dayOfWeek + ", " + theMonth + " " + dater.getDate() + ", " + dater.getFullYear();
  var doc = DocumentApp.getActiveDocument();

  var tables = doc.getTables();

  var latestTable = tables[0].copy();

  for (var i = 1; i < 8.; i++)
  {
      var todayWork = latestTable.getCell(i,2).getText();

      var yesterdayCell = latestTable.getCell(i,1);
      var todayCell = latestTable.getCell(i,2);

      yesterdayCell.clear()          

      var listCount = todayCell.getNumChildren();

      for(var x = 0; x < listCount; x++)
      {
         var listText = todayCell.getChild(x).asText().getText();
         yesterdayCell.appendListItem(listText).setGlyphType(DocumentApp.GlyphType.BULLET);
      }

      todayCell.clear();


      todayCell.appendListItem("").setGlyphType(DocumentApp.GlyphType.BULLET);
  }

  doc.insertTable(0, latestTable) 
  doc.getBody().insertParagraph(0, paragraph).setBold(true).setFontSize(12);
  doc.saveAndClose();
}

任何帮助表示赞赏。谢谢

4

1 回答 1

1

在对 google plus 社区进行了一些反馈之后,事实证明我在 onLoad 中缺少函数名称的引号。

UI.createMenu("StandUp").addItem("昨天迁移", DoMigrate).addToUi();

本来应该

UI.createMenu("StandUp").addItem("昨天迁移", "DoMigrate").addToUi();

于 2013-05-21T01:28:02.623 回答