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

Wednesday, October 5, 2022

[FIXED] How to add comma in dropdown list values?

 October 05, 2022     excel, php, phpexcel     No comments   

Issue

I try to build a dropdown list with PHPExcel (v1.7.9), but values with comma are not exported correctly

For example : if i want to export these two values : "12" and "5,9", the dropdown list I want is :

12
5,9

But i Obtain this :

12
5
9

And i found none answer on the web to this problem.

Have you an idea ?

$objValidation = $excel->getActiveSheet()->getCell($nextLetter . $beginLine)->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('Erreur');
$objValidation->setError('Cette valeur n\'est pas dans la liste');
$objValidation->setPromptTitle('Sélectionner la valeur :');
$objValidation->setPrompt('Merci de choisir une valeur dans la liste :');
$objValidation->setFormula1(/*????*/);

Solution

One solution would be to have a series of cells containing the possible values, and set the formula to that range:

// Set cells containing our possible list values
$objValidation = $objPHPExcel->getActiveSheet()
    ->setCellValueExplicit('A1', "12");
$objValidation = $objPHPExcel->getActiveSheet()
    ->setCellValueExplicit('A2', "9,5");

// Set the data validation list
$objValidation = $objPHPExcel->getActiveSheet()
    ->getCell("B1")->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('Erreur');
$objValidation->setError('Cette valeur n\'est pas dans la liste');
$objValidation->setPromptTitle('Sélectionner la valeur :');
$objValidation->setPrompt('Merci de choisir une valeur dans la liste :');
// Set the formula to the range of cells containing the list values
$objValidation->setFormula1('=A1:A2');

Another alternative would be to use a Unicode full width comma between 9 and 5 using U-FF0C



Answered By - Mark Baker
Answer Checked By - Katrina (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