单元格日期格式化

$worksheet->getStyle('AH'.$row)
      ->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_DATE_YYYYMMDD2);

单元格下拉列表,限定输入值

        $statusList = ['1' => '待结算', '2' => '已结算'];
        $statusList = implode(',', $statusList);
 
                    $objValidation1 = $worksheet->getCell('AG' . $row)
                        ->getDataValidation();
                    $objValidation1->setType(\PhpOffice\PhpSpreadsheet\Cell\DataValidation::TYPE_LIST)
                        ->setErrorStyle(\PhpOffice\PhpSpreadsheet\Cell\DataValidation::STYLE_INFORMATION)
                        ->setAllowBlank(false)
                        ->setShowInputMessage(true)
                        ->setShowErrorMessage(true)
                        ->setShowDropDown(true)
                        ->setErrorTitle('输入的值有误')
                        ->setError('您输入的值不在下拉框列表内.')
                        ->setPromptTitle('')
                        ->setPrompt('')
                        ->setFormula1('"' . $statusList . '"'); // 设置为变量内容
 
 
        foreach ($data as $item) {
            $column = 1;
 
            foreach ($item as $value) {
                $worksheet->setCellValueByColumnAndRow($column, $row, $value);
 
                if($column == 33 ){
                    $objValidation1 = $worksheet->getCell('AG' . $row)
                        ->getDataValidation();
                    $objValidation1->setType(\PhpOffice\PhpSpreadsheet\Cell\DataValidation::TYPE_LIST)
                        ->setErrorStyle(\PhpOffice\PhpSpreadsheet\Cell\DataValidation::STYLE_INFORMATION)
                        ->setAllowBlank(false)
                        ->setShowInputMessage(true)
                        ->setShowErrorMessage(true)
                        ->setShowDropDown(true)
                        ->setErrorTitle('输入的值有误')
                        ->setError('您输入的值不在下拉框列表内.')
                        ->setPromptTitle('')
                        ->setPrompt('')
                        ->setFormula1('"' . $statusList . '"'); // 设置为变量内容
                }
 
 
 
                $column++;
            }
            $row++;
        }

取消长数字科学计算法
方法①

$worksheet->setCellValueExplicitByColumnAndRow($column, $row, $value,\PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_STRING);

方法②
在单元格内容加上空格即可

发表评论

邮箱地址不会被公开。 必填项已用*标注