javascript - 将数据导出到文件 docx、node.js 和 react js
解决方案
你可以在 Python 中做到这一点。创建一个 Python 脚本并从 NodeJS 调用它。Python 有一些用于docx
操作的库。您可以使用的是python-docx-template
.
步骤1:
创建一个适合您的 Python 脚本。
第2步
您可以使用spawn
模块从 NodeJS 调用 Python 脚本。
const { spawn } = require('child_process');
const python_script = spawn('python', ['relative_path_to_python_script']);
python_script.stdin.write('You can send some inputs to Python script here');
python_script.stdin.end();
python_script.stdout.on('data', (data) => {
// data - output from Python script
// This will execute after the Python script finishes
});
python_script.stderr.on('data', (error) => {
// This will execute if Python script throws an error
});
推荐阅读
- ruby - Ruby Anagram 算法的时间和空间复杂度
- excel - 通过工作表自动化循环代码时发生错误异常
- xml - XSLT - 添加一个 IF 语句来检查 XML 的冒号
- ios - 如何找到 Xcode 10.1 的图像视图
- python - 打开 Json,替换值并运行 json.load
- javascript - 如何在 5 分钟的可控时间内显示一条消息
- c# - 在子类型接口和它的基类型接口之间转换,然后再转换回来,是一件坏事吗?
- python - 如何使用python将唯一值写入csv
- python-3.x - 计算两列之间的回归,然后移动到下一列,然后是接下来的两列,依此类推
- sql - PostgreSQL 中日期的数据类型