You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
wx.sstbc.com/app/Exports/SupplyDemandImportTemplate.php

24 lines
1.9 KiB

2 days ago
<?php
namespace App\Exports;
use Maatwebsite\Excel\Concerns\WithEvents;
use Maatwebsite\Excel\Events\AfterSheet;
use PhpOffice\PhpSpreadsheet\Cell\DataValidation;
class SupplyDemandImportTemplate extends SupplyDemandExport implements WithEvents
{
public function registerEvents(): array {
return [AfterSheet::class => function (AfterSheet $event) {
$sheet=$event->sheet->getDelegate();$sheet->freezePane('A2');
$sheet->getStyle('A1:J1')->getFont()->setBold(true);
foreach (['A'=>14,'B'=>28,'C'=>60,'D'=>32,'E'=>16,'F'=>30,'G'=>20,'H'=>22,'I'=>24,'J'=>32] as $col=>$width) $sheet->getColumnDimension($col)->setWidth($width);
$tips=['A'=>'必填:下拉选择供应、需求或投融资。','C'=>'必填:详细内容,不受200字限制,最多10000字。','D'=>'选填:多个标签使用“、”分隔,例如:新能源、新材料。','G'=>'必填:11位手机号,用于绑定学员;不公开。','H'=>'选填:到期日期格式为2027-01-31,到期当天仍有效;留空为长期有效。','I'=>'选填:微信号,不公开。','J'=>'选填:邮箱地址,不公开。'];
foreach ($tips as $col=>$tip) $sheet->getComment($col.'1')->getText()->createTextRun($tip);
for($row=2;$row<=1001;$row++) {
$v=$sheet->getCell('A'.$row)->getDataValidation();
$v->setType(DataValidation::TYPE_LIST)->setErrorStyle(DataValidation::STYLE_STOP)->setAllowBlank(false)->setShowDropDown(true)->setShowErrorMessage(true)->setErrorTitle('供需类型不正确')->setError('请选择供应、需求或投融资')->setFormula1('"供应,需求,投融资"');
foreach(['D','H'] as $col) $sheet->getCell($col.$row)->getDataValidation()->setShowInputMessage(true)->setPromptTitle($col==='D'?'行业标签':'有效期')->setPrompt($tips[$col]);
}
$sheet->getStyle('G2:J1001')->getNumberFormat()->setFormatCode('@');
}];
}
}