PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, October 5, 2022

[FIXED] How to increase cell character limit PHPExcel TYPE LIST

 October 05, 2022     php, phpexcel     No comments   

Issue

Using PHPExcel to create a dropdown list like so:

$objValidation = $objPHPExcel->getActiveSheet()->getCell("A".$i)->getDataValidation();
$objValidation->setType( \PHPExcel_Cell_DataValidation::TYPE_LIST );
$objValidation->setErrorStyle( \PHPExcel_Cell_DataValidation::STYLE_INFORMATION );
$objValidation->setAllowBlank(false);
$objValidation->setShowInputMessage(true);
$objValidation->setShowErrorMessage(true);
$objValidation->setShowDropDown(true);
$objValidation->setErrorTitle('Input error');
$objValidation->setError('Value is not in list.');
$objValidation->setPromptTitle('Pick from list');
$objValidation->setPrompt('Please pick a value from the drop-down list.');
$formulaString = '"' .  implode(", ", $items_array) . '"';
$objValidation->setFormula1($formulaString);

$objWriter = new \PHPExcel_Writer_Excel2007($objPHPExcel);
$filename = "MyExcel.xlsx";
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="'.$filename.'"');
header('Cache-Control: max-age=0');
$objWriter->save('php://output');

The problem is it cuts off at 1023 characters hence breaking the "dropdown" function.

How do I increase the character limit?


Solution

As discussed in the comments, there is a limit to the length of a static list in data validation.

You should put the validation data in a range in the workbook somewhere and provide this range for the validation:

// Get options from another sheet
$objvalidation->setFormula1('ExampleSheet!A1:A100');


Answered By - Phylogenesis
Answer Checked By - Dawn Plyler (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing