Protected sheet + Unprotected cell + Data Validation = Crash Excel

Topics: Developer Forum, User Forum
Feb 24, 2009 at 5:57 PM
Hi,

The following code will make Microsoft Excel 2007 crash:
<?php
set_include_path(get_include_path() . PATH_SEPARATOR . '../functies/');
include 'PHPExcel.php';
include 'PHPExcel/IOFactory.php';

$report = new PHPExcel();

$report->getActiveSheet()->getProte
ction()->setSheet(true);
$report->getSecurity()->setLockWindows(true);
$report->getSecurity()->setLockStructure(true);
$report->getSecurity()->setWorkbookPassword("test");

$report->setActiveSheetIndex(0);

$report->getActiveSheet()->getStyle('B3')->getProtection()->setLocked(
PHPExcel_Style_Protection::PROTECTION_UNPROTECTED
);

$objValidation = $report->getActiveSheet()->getCell('B3')->getDataValidation();
$objValidation->setType( PHPExcel_Cell_DataValidation::TYPE_WHOLE );
$objValidation->setErrorStyle( PHPExcel_Cell_DataValidation::STYLE_STOP );
$objValidation->setAllowBlank(true);
$objValidation->setShowInputMessage(true);
$objValidation->setShowErrorMessage(true);
$objValidation->setErrorTitle('Fout bij ingeven');
$objValidation->setError('Uw invoer is niet geldig.');
$objValidation->setPromptTitle('Toegestane invoer');
$objValidation->setPrompt('Enkel cijfers tussen 0 en 10 zijn toegelaten.');
$objValidation->setFormula1(0);
$objValidation->setFormula2(10);
$report->getActiveSheet()->getCell('B3')->setDataValidation($objValidation);

header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="myfile.xlsx"');
header('Cache-Control: max-age=0');

$objWriter = PHPExcel_IOFactory::createWriter($report, 'Excel2007');
$objWriter->save('php://output');
?>

So what I do is: I create a new protected worksheet, and unprotect cell B3.
Then I make sure that the input of B3 is validated. (a number between 0 and 10). This makes Excel crash.

Does anybody has an idea what goes wrong? Is it a bug?

I accidently made a bug report with the text above. I intended to make a thread instead of a bug report. But if it's a bug, maybe that was the right thing to do. If not, I'm really sorry
Developer
Feb 24, 2009 at 6:49 PM
I believe we need to take some action on this. Thank you for your report.
http://www.codeplex.com/PHPExcel/WorkItem/View.aspx?WorkItemId=9343