使用 typescript 在 word 加载项中创建下拉列表
to create dropdown in word add-in using typescript
我想使用 angular 打字稿在 word 加载项中创建一个下拉列表,其中包含选项 yes 和 no 以及特定选项的选择。我想在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));
}
});
}
我想使用 angular 打字稿在 word 加载项中创建一个下拉列表,其中包含选项 yes 和 no 以及特定选项的选择。我想在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));
}
});
}