我正在创建一个应该包含下拉列表的excel模板.我看到它可能与PHPexcel库(
PHPExcel Multiple Dropdown list that dependent).
我想知道是否可以使用 maatwebsite提供的laravel-excel库.
我需要下拉式功能,NamedRange,datavalidation,setFormula等功能的语法
我想知道是否可以使用 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'); }