const mysqlx = require("@mysql/xdevapi");
const path = "E:\\微信文档\\WeChat Files\\mxds123456\\FileStorage\\File\\2020-03\\101-200";
const fs = require('fs');
const iconv = require("iconv-lite");
var mammoth = require("mammoth");
fs.readdir( path, (err, files)=> // 读取文件夹下所有文件名(返回数组)
{
if(files.length > 0)
{
console.log(files.length);
files = files.splice(6, 93);
console.log(files.length);
for(let i = 0; i < files.length; i++)
{
{
const pathContent = `${path}\\${ files[i] }`;
console.log(pathContent);
mammoth.extractRawText({path: pathContent}) //读取docx文件
.then(function(result)
{
execute_mysql( files[i].slice(0, 3), result.value);
})
.catch(e => console.log(e))
.done();
}
}
}
});
async function execute_mysql(name, report)
{
console.log(name, report);
const mysqlx = require("@mysql/xdevapi");
const session = await mysqlx.getSession({
user: 'root',
password: '123456',
host: 'localhost',
port: '33060'
});
const sql = `insert into test1.patient_report(name, report) values( "${name}", "${ report }" )`;
console.log(sql);
await session.sql(sql).execute( r=> console.log(r) );
await session.close();
}
来源:CSDN
作者:tcllxxl
链接:https://blog.csdn.net/tcllxxl/article/details/104756294