美文网首页
如何将富文本/html导出为word文档

如何将富文本/html导出为word文档

作者: 时光已翩然轻擦 | 来源:发表于2024-04-28 17:25 被阅读0次

一、 html-docx-js-typescript

1. 安装

# npm install html-docx-js-typescript --save-dev

2. vue中的使用方法

import { asBlob } from 'html-docx-js-typescript'
// 如果你想保存为docx格式,你还需要import 'file-saver'
import { saveAs } from 'file-saver'

const content = '......' // 要导出的富文本内容
const html= `
  <!DOCTYPE html>
  <html>
    <head>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    </head>
    <body>
       ${content} // 富文本的内容
    </body>
  </html>
  `

export default {
  methods: {
    saveDocx() {
      asBlob(html).then(data => {
        saveAs(data, '文件名.docx') // 保存为 docx 文件
      }) // asBlob() return Promise<Blob|Buffer>
    }
  }
}

参考资料

本站相关内容

相关文章

网友评论

      本文标题:如何将富文本/html导出为word文档

      本文链接:https://www.haomeiwen.com/subject/bagzxjtx.html