將html中的內容匯出為word檔案
阿新 • • 發佈:2020-10-10
用jquery.js方法
第一步,先引入三個js檔案
<script src="js/jquery.js"></script>
<script src="js/FileSaver.js"></script>
<script src="js/jquery.wordexport.js"></script>
要先引入上面的兩個檔案再引入 wordexport
檔案
下載地址:
https://github.com/eligrey/FileSaver.js/
https://github.com/markswindoll/jQuery-Word-Export
我把原始碼附上吧,找來找去還挺麻煩的
FileSaver.js的原始碼
第二步,將要下載的內容寫在一個id上(後續通過id獲取想要下載的內容)
如
<div id='download'>測試測試測試測試測試</div>
樣式要寫到行內
第三步,寫文字繫結下載事件
<button class='dd' onclick="dowload();" style="width: 55px">下載</button> `function dowload(){ $("#dd").hide(); $('#download').wordExport('檢查記錄表'); }
- 官方是這樣寫的(很jquery,哈哈)
<button id=“export">匯出</button>
$("#export").click(function(){
$("#download").wordExport();
});
```這目前是我接手一個需要下載一個表格時用到的,先簡單記錄下,查閱資料發現還有下載圖片,echarts表格的,需要先將ECharts儲存為圖片,儲存到專案中固定的資料夾下,再將圖片地址賦值到src中,後期遇到再詳細記錄和補充