js生成word
下载依赖
javascript
npm install html-docx-js
引入
javascript
import htmlDocx from 'html-docx-js/dist/html-docx';
代码
javascript
//参数 html 文件名字 下载完执行回调函数
function html2word (html,fileName,callback){
const converted = htmlDocx.asBlob(html);
const link = document.createElement('a');
link.href = URL.createObjectURL(converted);
link.download = fileName?fileName+'.docx':'document.docx';
link.click();
callback&&callback()
}