mirror of
https://github.com/retailcrm/PHPExcel.git
synced 2024-11-29 00:36:02 +03:00
Data validation example limiting the length of text that can be entered in a cell
This commit is contained in:
parent
5e89b26e9d
commit
7d1c140974
@ -765,6 +765,22 @@ $objValidation->setFormula1(10);
|
|||||||
$objValidation->setFormula2(20);
|
$objValidation->setFormula2(20);
|
||||||
```
|
```
|
||||||
|
|
||||||
|
This validation will limit the length of text that can be entered in a cell to 6 characters.
|
||||||
|
|
||||||
|
```
|
||||||
|
$objValidation = $objPHPExcel->getActiveSheet()->getCell('B9')->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);
|
||||||
|
```
|
||||||
|
|
||||||
The following piece of code only allows an item picked from a list of data to be entered in cell B3:
|
The following piece of code only allows an item picked from a list of data to be entered in cell B3:
|
||||||
|
|
||||||
```php
|
```php
|
||||||
|
@ -70,6 +70,7 @@ $objPHPExcel->getActiveSheet()->setCellValue('A1', "Cell B3 and B5 contain data
|
|||||||
->setCellValue('D4', "Item #3")
|
->setCellValue('D4', "Item #3")
|
||||||
->setCellValue('D5', "Item #4")
|
->setCellValue('D5', "Item #4")
|
||||||
->setCellValue('D6', "Item #5")
|
->setCellValue('D6', "Item #5")
|
||||||
|
->setCellValue('A9', 'Text:')
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|
||||||
@ -114,6 +115,18 @@ $objValidation->setPromptTitle('Pick from list');
|
|||||||
$objValidation->setPrompt('Please pick a value from the drop-down list.');
|
$objValidation->setPrompt('Please pick a value from the drop-down list.');
|
||||||
$objValidation->setFormula1('$D$2:$D$6'); // Make sure NOT to put a range of cells or a formula between " and " !!!
|
$objValidation->setFormula1('$D$2:$D$6'); // Make sure NOT to put a range of cells or a formula between " and " !!!
|
||||||
|
|
||||||
|
$objValidation = $objPHPExcel->getActiveSheet()->getCell('B9')->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);
|
||||||
|
|
||||||
|
|
||||||
// Set active sheet index to the first sheet, so Excel opens this as the first sheet
|
// Set active sheet index to the first sheet, so Excel opens this as the first sheet
|
||||||
$objPHPExcel->setActiveSheetIndex(0);
|
$objPHPExcel->setActiveSheetIndex(0);
|
||||||
|
@ -70,6 +70,7 @@ $objPHPExcel->getActiveSheet()->setCellValue('A1', "Cell B3 and B5 contain data
|
|||||||
->setCellValue('D4', "Item #3")
|
->setCellValue('D4', "Item #3")
|
||||||
->setCellValue('D5', "Item #4")
|
->setCellValue('D5', "Item #4")
|
||||||
->setCellValue('D6', "Item #5")
|
->setCellValue('D6', "Item #5")
|
||||||
|
->setCellValue('A9', 'Text:')
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|
||||||
@ -115,6 +116,18 @@ $objValidation->setPromptTitle('Pick from list');
|
|||||||
$objValidation->setPrompt('Please pick a value from the drop-down list.');
|
$objValidation->setPrompt('Please pick a value from the drop-down list.');
|
||||||
$objValidation->setFormula1('$D$2:$D$6'); // Make sure NOT to put a range of cells or a formula between " and " !!!
|
$objValidation->setFormula1('$D$2:$D$6'); // Make sure NOT to put a range of cells or a formula between " and " !!!
|
||||||
|
|
||||||
|
$objValidation = $objPHPExcel->getActiveSheet()->getCell('B9')->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);
|
||||||
|
|
||||||
|
|
||||||
// Set active sheet index to the first sheet, so Excel opens this as the first sheet
|
// Set active sheet index to the first sheet, so Excel opens this as the first sheet
|
||||||
$objPHPExcel->setActiveSheetIndex(0);
|
$objPHPExcel->setActiveSheetIndex(0);
|
||||||
|
Loading…
Reference in New Issue
Block a user