[vue] html导出到word ,使用 htmlDocx FileSaver

npm install html-docx-js -S
npm install file-saver -S

file-saver是用来保存文件的,也是必须安装的。

import FileSaver from 'file-saver'
import htmlDocx from "html-docx-js/dist/html-docx"
//模板word导出
    exportWordTpl() {
        let contentHtml = document.getElementById("exportBox").innerHTML
      let content = `
            
                
            
            
                ${contentHtml}
            
`;
let converted = htmlDocx.asBlob(content);
FileSaver.saveAs(converted, '模块汇总表.docx');
}

参考:

vue中html导出到word

你可能感兴趣的:(#,vue,vue.js,html,word)