项目需求 有空就尝试使用vue去构建一个excel addin
微软太坑爹了,只给了ng react jquery的教程
文档会尝试中英文双语的html
在这篇文章,你能够看到是如何使用Vue和Excel的JavaScript API来构建一个Excel add-in的vue
npm install --global vue-cli
复制代码
npm install -g yo generator-office
复制代码
使用vue-cli来搭建脚手架,在命令行输入以下命令: vue init webpack vue-excel-addin
react
每一个add-in都须要一个manifest文件来配置和定义它的功能jquery
cd vue-excel-addin
yo office
生成工具会问你是否须要打开 resource.html.这篇文档无需打开, 固然若是你好奇的话,打开也不要紧! 选择 yes 或者 no 让生成工具完成它的工做把! webpack
<script>
标签添加到</head>
以前<script src="https://appsforoffice.microsoft.com/lib/1/hosted/office.js"></script>
复制代码
new Vue({ el: '#app', components: {App}, template: '<App/>' })
替换成如下Office.initialize = () => {
new Vue({
el: '#app',
components: {App},
template: '<App/>'
})
}
复制代码
<template>
<div id="app">
<div id="content">
<div id="content-header">
<div class="padding">
<h1>Hello world!</h1>
</div>
</div>
<div id="content-main">
<div class="padding">
<p>Choose the button below to set the color of the selected range to green.</p>
<br/>
<h3>Try it out</h3>
<button @click="onSetColor">Set color</button>
</div>
</div>
</div>
</div>
</template>
<script>
export default {
name: 'App',
methods: {
onSetColor() {
window.Excel.run(async (context) => {
const range = context.workbook.getSelectedRange()
range.format.fill.color = 'green';
await context.sync()
})
}
}
}
</script>
<style>
#content-header {
background: #2a8dd4;
color: #fff;
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 80px;
overflow: hidden;
}
#content-main {
background: #fff;
position: fixed;
top: 80px;
left: 0;
right: 0;
bottom: 0;
overflow: auto;
}
.padding {
padding: 15px;
}
</style>
复制代码
npm start
git
npm start
github
在Excel中的开始tab, 选择Show Taskpane按钮来打开add-in的task pane web
选择任意一个区域的单元格vue-cli
在task pane内, 点击 Set color按钮来将选中区域的颜色转为绿色npm