Script to automatically make a copy of a Google Document for editing

前端 未结 4 819
别那么骄傲
别那么骄傲 2021-02-01 21:35

I feel like a total noob posting here. I know CSS, HTML, and XML pretty well but have always avoided JS. I know very little javascript and recently started a Lynda.com course

4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-01 22:03

    Here is the code to do it properly (works in 2019,2020,2021):

    /**
     * Create custom menu when document is opened.
     */
    function onOpen() {
      DocumentApp.getUi()
        .createMenu('For Students')
        .addItem('Make a copy', 'makeACopy')
        .addToUi();
    }
    
    function makeACopy() {
      var templateId = DocumentApp.getActiveDocument().getId();
      DriveApp.getFileById(templateId).makeCopy();
    }
    

提交回复
热议问题