mirror of
https://github.com/retailcrm/PHPExcel.git
synced 2024-11-24 22: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
|
||||||
|
@ -47,30 +47,31 @@ $objPHPExcel = new PHPExcel();
|
|||||||
// Set document properties
|
// Set document properties
|
||||||
echo date('H:i:s') , " Set document properties" , EOL;
|
echo date('H:i:s') , " Set document properties" , EOL;
|
||||||
$objPHPExcel->getProperties()->setCreator("Maarten Balliauw")
|
$objPHPExcel->getProperties()->setCreator("Maarten Balliauw")
|
||||||
->setLastModifiedBy("Maarten Balliauw")
|
->setLastModifiedBy("Maarten Balliauw")
|
||||||
->setTitle("Office 2007 XLSX Test Document")
|
->setTitle("Office 2007 XLSX Test Document")
|
||||||
->setSubject("Office 2007 XLSX Test Document")
|
->setSubject("Office 2007 XLSX Test Document")
|
||||||
->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")
|
->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")
|
||||||
->setKeywords("office 2007 openxml php")
|
->setKeywords("office 2007 openxml php")
|
||||||
->setCategory("Test result file");
|
->setCategory("Test result file");
|
||||||
|
|
||||||
|
|
||||||
// Create a first sheet
|
// Create a first sheet
|
||||||
echo date('H:i:s') , " Add data" , EOL;
|
echo date('H:i:s') , " Add data" , EOL;
|
||||||
$objPHPExcel->setActiveSheetIndex(0);
|
$objPHPExcel->setActiveSheetIndex(0);
|
||||||
$objPHPExcel->getActiveSheet()->setCellValue('A1', "Cell B3 and B5 contain data validation...")
|
$objPHPExcel->getActiveSheet()->setCellValue('A1', "Cell B3 and B5 contain data validation...")
|
||||||
->setCellValue('A3', "Number:")
|
->setCellValue('A3', "Number:")
|
||||||
->setCellValue('B3', "10")
|
->setCellValue('B3', "10")
|
||||||
->setCellValue('A5', "List:")
|
->setCellValue('A5', "List:")
|
||||||
->setCellValue('B5', "Item A")
|
->setCellValue('B5', "Item A")
|
||||||
->setCellValue('A7', "List #2:")
|
->setCellValue('A7', "List #2:")
|
||||||
->setCellValue('B7', "Item #2")
|
->setCellValue('B7', "Item #2")
|
||||||
->setCellValue('D2', "Item #1")
|
->setCellValue('D2', "Item #1")
|
||||||
->setCellValue('D3', "Item #2")
|
->setCellValue('D3', "Item #2")
|
||||||
->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:')
|
||||||
|
;
|
||||||
|
|
||||||
|
|
||||||
// Set data validation
|
// Set data validation
|
||||||
@ -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);
|
||||||
|
@ -47,30 +47,31 @@ $objPHPExcel = new PHPExcel();
|
|||||||
// Set document properties
|
// Set document properties
|
||||||
echo date('H:i:s') , " Set document properties" , EOL;
|
echo date('H:i:s') , " Set document properties" , EOL;
|
||||||
$objPHPExcel->getProperties()->setCreator("Maarten Balliauw")
|
$objPHPExcel->getProperties()->setCreator("Maarten Balliauw")
|
||||||
->setLastModifiedBy("Maarten Balliauw")
|
->setLastModifiedBy("Maarten Balliauw")
|
||||||
->setTitle("Office 2007 XLSX Test Document")
|
->setTitle("Office 2007 XLSX Test Document")
|
||||||
->setSubject("Office 2007 XLSX Test Document")
|
->setSubject("Office 2007 XLSX Test Document")
|
||||||
->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")
|
->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")
|
||||||
->setKeywords("office 2007 openxml php")
|
->setKeywords("office 2007 openxml php")
|
||||||
->setCategory("Test result file");
|
->setCategory("Test result file");
|
||||||
|
|
||||||
|
|
||||||
// Create a first sheet
|
// Create a first sheet
|
||||||
echo date('H:i:s') , " Add data" , EOL;
|
echo date('H:i:s') , " Add data" , EOL;
|
||||||
$objPHPExcel->setActiveSheetIndex(0);
|
$objPHPExcel->setActiveSheetIndex(0);
|
||||||
$objPHPExcel->getActiveSheet()->setCellValue('A1', "Cell B3 and B5 contain data validation...")
|
$objPHPExcel->getActiveSheet()->setCellValue('A1', "Cell B3 and B5 contain data validation...")
|
||||||
->setCellValue('A3', "Number:")
|
->setCellValue('A3', "Number:")
|
||||||
->setCellValue('B3', "10")
|
->setCellValue('B3', "10")
|
||||||
->setCellValue('A5', "List:")
|
->setCellValue('A5', "List:")
|
||||||
->setCellValue('B5', "Item A")
|
->setCellValue('B5', "Item A")
|
||||||
->setCellValue('A7', "List #2:")
|
->setCellValue('A7', "List #2:")
|
||||||
->setCellValue('B7', "Item #2")
|
->setCellValue('B7', "Item #2")
|
||||||
->setCellValue('D2', "Item #1")
|
->setCellValue('D2', "Item #1")
|
||||||
->setCellValue('D3', "Item #2")
|
->setCellValue('D3', "Item #2")
|
||||||
->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:')
|
||||||
|
;
|
||||||
|
|
||||||
|
|
||||||
// Set data validation
|
// Set data validation
|
||||||
@ -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