php – Laravel excel库(Maatwebsite):如何在导出中创建一个下拉列表

前端之家收集整理的这篇文章主要介绍了php – Laravel excel库(Maatwebsite):如何在导出中创建一个下拉列表前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在创建一个应该包含下拉列表的excel模板.我看到它可能与PHPexcel库( PHPExcel Multiple Dropdown list that dependent).
我想知道是否可以使用 maatwebsite提供的laravel-excel库.
我需要下拉式功能,NamedRange,datavalidation,setFormula等功能的语法
public function index() {
        \Excel::create('file',function($excel) {
            require_once("/apppath//vendor/PHPoffice/PHPexcel/Classes/PHPExcel/NamedRange.PHP");
            require_once("/apppath/vendor/PHPoffice/PHPexcel/Classes/PHPExcel/Cell/DataValidation.PHP");

            $excel->sheet('New sheet',function($sheet) {

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

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


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

                $sheet->SetCellValue("C1","Atlanta");
                $sheet->SetCellValue("C2","New York");
                $sheet->SetCellValue("C3","Los Angeles");
                $sheet->_parent->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(false);
                $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'); //note this!
            });
        })->download("xlsx");
        return view('home');
    }
原文链接:https://www.f2er.com/laravel/138791.html

猜你在找的Laravel相关文章