存在VLOOKUP时,PHPExcel将不会下载

问题描述

我试图在Laravel上使用PHPExcel,但是每当我添加VLOOKUP时,excel都不会生成或不会下载其内容,但是如果我删除VLOOKUP,excel似乎可以正常工作。

$excel=\Excel::create('file',function($excel) {
        // $excel->setPreCalculateFormulas(FALSE);
        $countries=[
            ["name" => "Afghanistan","code" => "AF"],["name" => "land Islands","code" => "AX"],["name" => "Albania","code" => "AL"],["name" => "Algeria","code" => "DZ"],["name" => "American Samoa","code" => "AS"],["name" => "AndorrA","code" => "AD"],["name" => "Angola","code" => "AO"],["name" => "Anguilla","code" => "AI"],["name" => "Antarctica","code" => "AQ"],["name" => "Antigua and Barbuda","code" => "AG"],["name" => "Argentina","code" => "AR"],["name" => "Armenia","code" => "AM"],["name" => "Aruba","code" => "AW"],["name" => "Australia","code" => "AU"],["name" => "Austria","code" => "AT"],["name" => "Azerbaijan","code" => "AZ"],["name" => "Bahamas","code" => "BS"],["name" => "Bahrain","code" => "BH"],["name" => "Bangladesh","code" => "BD"],["name" => "Barbados","code" => "BB"],["name" => "Belarus","code" => "BY"],["name" => "Belgium","code" => "BE"],["name" => "Belize","code" => "BZ"],["name" => "Benin","code" => "BJ"],["name" => "Bermuda","code" => "BM"],["name" => "Bhutan","code" => "BT"],["name" => "Bolivia","code" => "BO"],["name" => "Bosnia and Herzegovina","code" => "BA"]
        ];
        $employeeSheet=$excel->sheet('Employee',function($sheet) use ($countries) {

            $sheet->SetCellValue("A1","Empty");
            $sheet->SetCellValue("A2","UK");
            $sheet->SetCellValue("A3","USA");

            $sheet->getParent()->addNamedRange(
                    new \PHPExcel_NamedRange(
                    'countries',$sheet,'A1:A3'
                    )
            );


            $sheet->SetCellValue("B1","No Value");
            $sheet->SetCellValue("B2","Birmingham");
            $sheet->SetCellValue("B3","Leeds");
            $sheet->getParent()->addNamedRange(
                    new \PHPExcel_NamedRange(
                    'UK','B1:B3'
                    )
            );

            $sheet->SetCellValue("C1","Atlanta");
            $sheet->SetCellValue("C2","New York");
            $sheet->SetCellValue("C3","Los Angeles");
            $sheet->getParent()->addNamedRange(
                    new \PHPExcel_NamedRange(
                    'USA','C1:C3'
                    )
            );
            $objValidation = $sheet->getCell('D1')->getDataValidation();
            $objValidation->setType(\PHPExcel_Cell_DataValidation::TYPE_LIST);
            $objValidation->setErrorStyle(\PHPExcel_Cell_DataValidation::STYLE_INFORMATION);
            $objValidation->setAllowBlank(true);
            $objValidation->setShowInputMessage(true);
            $objValidation->setShowErrorMessage(true);
            $objValidation->setShowDropDown(true);
            $objValidation->setErrorTitle('Input error');
            $objValidation->setError('Value is not in list.');
            $objValidation->setPromptTitle('Pick from list');
            $objValidation->setPrompt('Please pick a value from the drop-down list.');
            $objValidation->setFormula1('Countries!A1:A'.count($countries)); //note this!
            $sheet->SetCellValue('D1',$countries[0]['name']);
            // $sheet->getCell('D1')->getV
            $sheet->SetCellValue('E1','=VLOOKUP(D1,Countries!A1:B'.count($countries).',2,FALSE)');
        });
        $countrySheets=$excel->sheet('Countries',function($sheet) use ($countries) {
            foreach($countries as $key => $country) {
                $sheet->SetCellValue("A".($key+1),$country['name']);
                $sheet->SetCellValue("B".($key+1),$country['code']);
            }
        });

        // $employeeSheet->getActiveSheet()
        // $employeeSheet->getActiveSheet()->getCell('E1')->getCalculatedValue();
    });
    // $excel->setPreCalculateFormulas(FALSE);
    $excel->download('xlsx');

没有输出或已下载文件,但是storage/logs上存在日志错误 roduction.ERROR: Trying to access array offset on value of type null {"exception":"[object] (ErrorException(code: 0): Trying to access array offset on value of type null at /Users/user/Desktop/projects/hr-time-web/vendor/phpoffice/phpexcel/Classes/PHPExcel/Writer/Excel2007/Worksheet.php:1117)

VLOOKUP是否仍在PHPExcel上运行? 我阅读了文档,但没有评论或文档对初学者不友好

我正在使用PHPExcel 1.8版本。我读过其他与我的版本相同的文章,看来它们对他们有帮助,

我犯了什么错误?

更新: 我使用PHP电子表格解决了该问题。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)