有没有办法从文档中删除脚本(使用新的文档嵌入脚本) [英] Is there a way to remove a script from a doc (using the new doc embedded script)

查看:111
本文介绍了有没有办法从文档中删除脚本(使用新的文档嵌入脚本)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发了一个使用Google文档作为模板 AND作为脚本持有者的脚本扩展。

它为我提供了一个非常好的环境实施一个邮件合并应用程序(见下文)。
在某些时候,我使用 DocsList class makeCopy(new Name)来生成所有的文档被修改并发送。它就是这样:

  var docId = docById.makeCopy('doc _'+ Utilities.formatString(%03d, d))的getId(); 

一切都很好,但(当然)模板文档的每个副本都包含脚本的副本这显然没有必要!这也有点烦人,因为每次我打开副本来检查数据是否正确时,我会看到自动打开的边栏菜单,这是一个耗时的过程...



我的问题是:


  • 有没有办法从副本中删除嵌入的脚本? (这很简单)

  • 或者我应该将模板中的所有文档元素都复制到空白文档中? (这也是一种可行的方法,但我没有尝试,我不知道这个文档在现实生活中会用到什么......
    在任何情况下我都能得到一个完美的克隆吗?)
    我读过文档,没有找到任何相关的线索,但是谁知道?可能我错过了一些明显的东西;)
  • 下面是一个缩小的屏幕截图,用于显示此问题的上下文:
  • b
    $ b

    继Henrique的建议之后,我使用了一种避免用户界面在新创建的文档上加载的解决方法......(感谢Henrique,这很聪明; - )

    b
    $ b

    现在由onOpen调用的函数如下所示:

      function showFields() {
    var doc = DocumentApp.getActiveDocument();
    var body = doc.getBody();
    var find = body.findText('#'); //新文档不再有字段标记。
    if(find!= null){//仅当文档中存在标记时才显示UI。
    var html = HtmlService.createHtmlOutputFromFile('index')
    .setTitle(Outils de l'option Publipostage)。setWidth(370);
    ui.showSidebar(html);
    }
    }


    I developed a script extension that uses a Google doc as template AND as script holder.

    It gives me a very nice environment to implement a mail merge application (see below). At some point I use the DocsList class makeCopy(new Name) to generate all the docs that will be modified and sent. It goes simply like that :

    var docId=docById.makeCopy('doc_'+Utilities.formatString("%03d",d)).getId();
    

    Everything works quite nicely but (of course) each copy of the template doc contains a copy of the script which is obviously not necessary ! It is also a bit annoying since each time I open a copy to check if data are right I get the sidebar menu that opens automatically which is a time consuming process ...

    My question is (are) :

    • is there any way to remove the embedded script from the copy ? (that would be simple)
    • or should I copy all the doc elements from the template to an empty document ? (which is also a possible way to go but I didn't try and I don't know what will be in this doc in real life use... Shall I get a perfect clone in any case ?) I've read the doc and didn't find any relevant clue but who knows ? maybe I missed something obvious ;-)

    below is a reduced screen capture to show the context of this question :

    解决方案

    Following Henrique's suggestion I used a workaround that prevents the UI to load on newly created documents... (thanks Henrique, that was smart ;-)

    The function that is called by onOpen now goes like that :

    function showFields() {
      var doc = DocumentApp.getActiveDocument();
      var body = doc.getBody();
      var find = body.findText('#'); // the new docs have no field markers anymore. 
      if(find != null){  // show the UI only if markers are present in the document.
      var html = HtmlService.createHtmlOutputFromFile('index')
          .setTitle("Outils de l'option Publipostage").setWidth(370);
      ui.showSidebar(html);
      }
    }
    

    这篇关于有没有办法从文档中删除脚本(使用新的文档嵌入脚本)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆