【问题标题】:Laravel Excel handle error when file is open文件打开时 Laravel Excel 处理错误
【发布时间】:2018-11-30 10:47:12
【问题描述】:

我在本地项目中使用 Laravel Excel 2.1.0 将一行写入 excel 文件。

这是我的代码:

$filePath = storage_path('myfile.xls');
$rows = \Excel::load($filePath, function($reader) {
    $sheet = $reader->sheet(0);
    $sheet->appendRow(
        array(
             'Hello'
        )
    );
});

一切正常,我的文件中添加了一个新行。

有时可能会在用户尝试追加新行时打开 excel 文件。在这种情况下,Laravel 正确地告诉我这个错误:

fopen(mypath\myfile.xls): failed to open stream: Resource temporarily unavailable

如何处理此错误以跳过该函数并继续执行我的代码而不附加行?

【问题讨论】:

    标签: laravel laravel-excel


    【解决方案1】:

    我是这样解决的:

    $filePath = storage_path('myfile.xls');
    $fp = @fopen($filePath, "r+");
    if($fp) {
        $rows = \Excel::load($filePath, function($reader) {
            $sheet = $reader->sheet(0);
            $sheet->appendRow(
                array(
                     'Hello'
                )
            );
        });
    }
    

    【讨论】:

      猜你喜欢
      • 2014-03-17
      • 2014-02-11
      • 1970-01-01
      • 1970-01-01
      • 2023-04-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多