我有一个功能,它将读取 excel 文档并将内容写入文件。编写完成后,我将调用 resolve,调用函数会将文件下载给用户。
但是在完成其他功能之前会调用resolve,因此下载时文件将为空。
var downloadFile = (oracledb, connectionAttributes, responsem, files) => {
return new Promise((resolve, reject) => {
oracledb.getConnection(connectionAttributes, (error, connection) => {
var completed = false;
if (error) {
reject(response.send(`Cannot establish connection${JSON.stringify(connectionAttributes,undefined,2)}`));
return;
} else if (connection) {
//result will have all the sheets data.
result[sheet1].forEach((element) => {
//code to add all the data to file by reading sheet data.
});
result[sheet2].forEach((element) => {
//code to add all the data to file by reading sheet data.
});
resolve();
}
});
});}
caller function code-> downloadFile().then((resolved) => {
response.download(filePath);
}, (reject) => {
console.log(reject);
});