PHPExcel - 如何设置单元格的文本长度?

时间:2016-03-14 07:03:32

标签: laravel phpexcel

如何设置单元格的文本长度,以便在导出文件后编辑该单元格时没有人可以超过该长度?

1 个答案:

答案 0 :(得分:1)

您可以查看PHPExcel中data validation rulesTYPE_TEXTLENGTH选项

$objValidation = $objPHPExcel->getActiveSheet()
    ->getCell('A1')
    ->getDataValidation();
$objValidation->setType( PHPExcel_Cell_DataValidation::TYPE_TEXTLENGTH );
$objValidation->setErrorStyle( PHPExcel_Cell_DataValidation::STYLE_STOP );
$objValidation->setAllowBlank(true);
$objValidation->setShowInputMessage(true);
$objValidation->setShowErrorMessage(true);
$objValidation->setErrorTitle('Input error');
$objValidation->setError('Text exceeds maximum length');
$objValidation->setPromptTitle('Allowed input');
$objValidation->setPrompt('Maximum text length is 6 characters.');
$objValidation->setFormula1(6);