Files
plugins_vue/src/pages/page1/components/HelloWorld.vue
T
2024-09-23 15:40:22 +08:00

131 lines
4.2 KiB
Vue

<template>
<div id="helloWorld">
<a-button-group>
<a-button @click="handleDeleteBlockLVlSdt">cxx-删除全部BlockLVlSdt</a-button>
<a-button @click="handleDuanluo">cxx-插入段落编号</a-button>
</a-button-group>
<a-button-group>
<a-button @click="handleHelloWorld">cxx-插入文本</a-button>
<a-button @click="handleDuanluo">cxx-插入段落编号</a-button>
</a-button-group>
<a-button-group>
<a-button @click="handleReadOnlyBlock">cxx-插入只读文本</a-button>
<a-button @click="handleSetting">cxx-设置文字样式</a-button>
</a-button-group>
<a-button-group>
<a-button @click="handleLiexiang">cxx-插入列项</a-button>
<a-button @click="handleTest1">cxx-固定格式区域</a-button>
</a-button-group>
</div>
</template>
<script>
import moment from 'moment'
export default {
name: 'HelloWorld',
methods: {
handleDeleteBlockLVlSdt() {
this.ctx.callCommand(() => {
oDocument = Api.GetDocument();
oParagraph = oDocument.GetElement(0);
oContentControls = oDocument.GetAllContentControls();
console.log(oContentControls)
for (let i = 0; i < oContentControls.length; i++) {
try {
oContentControls[0].Delete();
} catch(e) {
console.log('del err:', e)
}
}
})
},
handleHelloWorld() {
const text = 'Hello world!'
window.Asc.scope.text = text // export variable to plugin scope
this.ctx.callCommand(() => {
const oDocument = Api.GetDocument()
const oParagraph = Api.CreateParagraph()
oParagraph.AddText(Asc.scope.text)
oDocument.InsertContent([oParagraph])
}, false)
},
handleDuanluo() {
this.ctx.callCommand(() => {
const oDocument = Api.GetDocument();
const oNumbering = oDocument.CreateNumbering("test");
for (nLvl = 0 ; nLvl < 5 ; ++nLvl) {
oNumLvl = oNumbering.GetLevel(nLvl);
oParagraph = Api.CreateParagraph();
oParagraph.AddText( "这是带项目符号的示例" + (nLvl + 1 ));
oParagraph.SetNumbering(oNumLvl);
oDocument.Push(oParagraph);
}
}, false)
},
handleReadOnlyBlock() {
window.Asc.scope.text = `当前时间是: ${moment(new Date()).format('YYYY-MM-DD HH:mm:ss')}`
this.ctx.callCommand(() => {
const oDocument = Api.GetDocument();
const oBlockLvlSdt = Api.CreateBlockLvlSdt();
oBlockLvlSdt.GetContent().GetElement(0).AddText(Asc.scope.text);
oBlockLvlSdt.SetLock( "sdtLocked" );
oDocument.AddElement( 0 , oBlockLvlSdt);
})
},
handleSetting() {
this.ctx.callCommand(() => {
const oDocument = Api.GetDocument();
const oBlockLvlSdt = Api.CreateBlockLvlSdt();
oBlockLvlSdt.GetContent().GetElement( 0 ).AddText( "这是一个块文本内容控件,字体大小设置为30,字体粗细设置为粗体。" );
oDocument.AddElement( 0 , oBlockLvlSdt);
oTextPr = oDocument.GetDefaultTextPr();
oTextPr.SetFontSize( 30 );
oTextPr.SetBold( true );
// oTextPr.SetCaps(true);
oBlockLvlSdt.SetTextPr(oTextPr);
})
},
handleLiexiang() {
this.ctx.callCommand(() => {
try {
oDocument = Api.GetDocument();
oParagraph = Api.CreateParagraph()
oParagraph.AddText("We create a 3x3 table and set the bold font weight to the text in cell #1:");
oDocument.AddElement(oParagraph)
} catch(e) {
console.log(e)
}
})
},
handleTest1() {
this.ctx.callCommand(() => {
try {
oDocument = Api.GetDocument();
oBlockLvlSdt = Api.CreateBlockLvlSdt();
oBlockLvlSdt.GetContent().GetElement(0)
.AddText("This is a block text content control with the content lock set to it.")
.SetBold(false)
.SetColor(0, 0, 255,false);
oBlockLvlSdt.SetLock("sdtLocked");
oDocument.AddElement(0, oBlockLvlSdt);
} catch(e) {
console.log(e)
}
})
}
}
}
</script>
<style lang="less" scoped>
#helloWorld {
margin-top: 10px;
}
</style>