我想使用具有"是又有"的Angular Typecript在Word加载项中创建一个下拉词,然后选择特定选项。我想在Word文档中添加一个段落。任何人都可以提出好方法。
首先,在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));
}
});
}