PHPOffice / PHPExcel

ARCHIVED
Other
11.46k stars 4.2k forks source link

Create in-cell dropdown list? #1335

Closed boonstoppel closed 6 years ago

boonstoppel commented 6 years ago

Hi,

is it possible to create an in-cell dropdown list via the PHPExcel library?

For example: http://d.pr/i/b49Juk/3VMAJy6o

Here an explanation how to do this in spreadsheets: https://support.google.com/docs/answer/186103

aliusa commented 6 years ago

I don't think it's possible in Excel. It's Google Docs feature.

boonstoppel commented 6 years ago

Found a solution.

$list = trim(implode(',', [ 'foo', 'bar, 'baz' ]));

$cell ->getDataValidation() ->setType(PHPExcel_Cell_DataValidation::TYPE_LIST) ->setErrorStyle(PHPExcel_Cell_DataValidation::STYLE_INFORMATION) ->setAllowBlank(true) ->setShowDropDown(true) ->setErrorTitle('Input error') ->setError('Value is not in list') ->setFormula1(sprintf('"%s"', $list));