我有一个React应用,我想将一些html内容导出到Word文档并下载。例如:
<div> Hello World!!!</div>
<input type="button" onClick={exportToWord()}/>
我正在搜索一个函数,该函数将处理带有文本Hello world !!!的Word文档!!。
您可以将redocx
的word documents
库与React
一起使用您可以通过NPM安装redocx
npm i redocx
此简单示例将在word doc
中呈现Hello World。>
import React from 'react' import { render, Document, Text } from 'redocx' class App extends React.Component { render() { return ( <Document> <Text>Hello World</Text> </Document> ) } } render(<App />, `${__dirname}/example.docx`)
对于演示,您可以克隆此存储库并在本地运行
git clone https://github.com/nitin42/redocx.git cd redocx npm install npm run example
您可以在这里找到所有文档redocx docs