gpt4 book ai didi

php - Laravel excel 库(Maat 网站): How to create a drop down list in exports

转载 作者:行者123 更新时间:2023-12-02 01:35:59 28 4
gpt4 key购买 nike

我正在创建一个 Excel 模板,其中应包含一个下拉列表。我认为使用 phpexcel 库( PHPExcel Multiple Dropdown list that dependent )是可能的。我想知道是否可以使用 maatwebsite 提供的 laravel-excel 库来完成。我需要 dropdown、NamedRange、datavalidation、setFormula 等函数的语法。

最佳答案

对于 maatwebite 版本 V.3.1 使用以下代码

<?php

namespace App\Exports;

use App\Models\Category;

use Illuminate\Contracts\View\View;
use Maatwebsite\Excel\Concerns\FromView;
use Maatwebsite\Excel\Concerns\WithEvents;
use Maatwebsite\Excel\Concerns\WithTitle;
use Maatwebsite\Excel\Events\AfterSheet;
use PhpOffice\PhpSpreadsheet\Cell\DataValidation;

class BulkUploadProductExport implements FromView, WithEvents , WithTitle
{


public function view(): View
{
return view('exports', [
'categories' => Category::all()
]);
}

public function title(): string
{
return 'bulkupload';
}

public function registerEvents(): array
{

//$event = $this->getEvent();
return [
AfterSheet::class => function (AfterSheet $event) {

/** @var Sheet $sheet */
$sheet = $event->sheet;

/**
* validation for bulkuploadsheet
*/

$sheet->setCellValue('B5', "SELECT ITEM");
$configs = "DUS800, DUG900+3xRRUS, DUW2100, 2xMU, SIU, DUS800+3xRRUS, DUG900+3xRRUS, DUW2100";
$objValidation = $sheet->getCell('B5')->getDataValidation();
$objValidation->setType(DataValidation::TYPE_LIST);
$objValidation->setErrorStyle(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('"' . $configs . '"');

}
];
}
}

关于php - Laravel excel 库(Maat 网站): How to create a drop down list in exports,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29815227/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com