excel4node的写入文件函数捕获错误并且不会传播给调用者。因此,我的应用程序无法确定写入文件是否成功。
我目前的解决方法如下:
let fs = require('fs')
try {
let filePath = 'blahblah'
fs.writeFileSync(filePath, '') // Try-catch is for this statement
excel4nodeWorkbook.write(filePath)
} catch (e) {
console.log('File save is not successful')
}
它有效,但我认为这是一种 hack,而且它在语义上不是正确的方式。我也测试了fs.access
and fs.accessSync
,但他们只检查权限,而不是资源的状态(忙碌/锁定)。
有什么建议可以在不修改 excel4node 源代码的情况下看起来和表现得更好吗?