我需要检查当前是否使用 PHPSpreadsheet 打开了 excel 文件。
我想到了一个解决方案,处理这条线 $writer->save(file_name)
进入 if else
条件,但仍然无法正常工作。
if($writer->save(file_name){
//file is open
}else{
//file is not open
}
我还能做些什么来解决我的问题?
最佳答案
I need to check if the excel file is currently open using PHPSpreadsheet.
检查文件是否打开并不是很有用,因为打开/关闭状态可能随时更改,或者失败可能是由其他文件系统问题引起的。
您需要做的是处理文件操作期间的故障,如下所示:
try {
$writer->save(file_name);
}
catch (Exception $e) {
echo 'Unable to save file. Please close any other applications(s) that are using it: [", $e->getMessage(), "]\n";
}
关于PhpSpreadsheet - 检查文件是否打开,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52042123/