根据html代码转换为word文件
1、下载file-saver、html-docx-js-typescript
npm install file-saver html-docx-js-typescript
2、
<span @click="downloadWordWithHtmlString()">导出doc</span>
<div id="eltable" ref="eltable" style="display: none"><tableborder="1"cellspacing="0"width="600"style="font-size: 12px; color: #000; text-align: center"><tr height="50"><td>列1</td><td>列2</td></tr><tr height="50"><td>1-1</td><td>1-2</td></tr><tr height="50"><td>2-1</td><td>2-2</td></tr></table>
</div>
import { saveAs } from 'file-saver'
import { asBlob } from 'html-docx-js-typescript'
downloadWordWithHtmlString() {// let eltable = this.$refs.eltable// let html = eltable.$el.innerHTMLlet html = document.getElementById('eltable').innerHTMLlet name = `${this.fieldName}-条件信息`let htmlString = `<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><title>Document</title></head><body>${html}</body></html>`asBlob(htmlString).then((data) => {saveAs(data, `${name}.doc`)})
}