代码之家  ›  专栏  ›  技术社区  ›  Vivek Singh

使用typescript在word插件中创建下拉列表

  •  0
  • Vivek Singh  · 技术社区  · 7 年前

    我想使用angular typescript在word插件中创建一个下拉列表,其中包含选项yes和no,以及选择特定选项。我想在word文档中添加一段。有谁能提出一个好办法吗。

    1 回复  |  直到 7 年前
        1
  •  0
  •   Vivek Singh    7 年前

    首先,在HTML中创建下拉列表

    <div>
    <select class="form-control" (change)="yesClicked($event.target.value)">
        <option value="choose" >choose option</option>
        <option value="Yes">Yes</option>
        <option value="No" >No</option>
        </select>
    

    然后添加类型脚本代码

       yesClicked(eventName:any){
        if(eventName=='Yes')
            {
                this.wordDocument.yesclicked();
            }
            else if(eventName =='No')
                {
    
                    this.wordDocument.Noclicked();
                }
    }
    

    然后定义函数

        yesclicked()
        {   
         Word.run(function (context) {
         var body = context.document.body;
         body.insertParagraph('Content of a new paragraph', 
         Word.InsertLocation.end);
          return context.sync().then(function () {
        console.log('Paragraph added at the end of the document body.');
          });  
         })   
         .catch(function (error) {
       console.log('Error: ' + JSON.stringify(error));
      if (error instanceof OfficeExtension.Error) {
        console.log('Debug info: ' + JSON.stringify(error.debugInfo));
       }
     });
    
     }