項目需求 有空就嘗試使用vue去構建一個excel addin
微軟太坑爹了,只給了ng react jquery的教程
文檔會嘗試中英文雙語的
在這篇文章,你能夠看到是如何使用Vue和Excel的JavaScript API來構建一個Excel add-in的html
npm install --global vue-cli
npm install -g yo generator-office
使用vue-cli來搭建腳手架,在命令行輸入以下命令:vue init webpack vue-excel-addin
vue
每一個add-in都須要一個manifest文件來配置和定義它的功能react
cd vue-excel-addin
jquery
yo office
webpack
生成工具會問你是否須要打開 resource.html.這篇文檔無需打開, 固然若是你好奇的話,打開也不要緊! 選擇 yes 或者 no 讓生成工具完成它的工做把!git
<script>
標籤添加到</head>
以前<script src="https://appsforoffice.microsoft.com/lib/1/hosted/office.js"></script>
`
new Vue({`
替換成如下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
github
npm start
web