Skip to content

DataValidation corrupted when written to Xlsx #290

Closed
@TerjeBr

Description

This is:

What is the expected behavior?

Data validation of cells should have the correct type and errorStyle.

What is the current behavior?

All data validation ends up with the type 'none'.
The error style is also garbled.

What are the steps to reproduce?

Please provide a Minimal, Complete, and Verifiable example of code that exhibits the issue without relying on an external Excel file or a web server:

<?php

require __DIR__ . '/vendor/autoload.php';

use PhpOffice\PhpSpreadsheet\Cell\DataValidation;

// Create new Spreadsheet object
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();

$workSheet = $spreadsheet->getActiveSheet();
$cell1 = $workSheet->getCell('A1');
$cell1->setValue(77);

$validation1 = $cell1->getDataValidation();
$validation1->setType(DataValidation::TYPE_WHOLE);
$validation1->setErrorStyle(DataValidation::STYLE_STOP);
$validation1->setAllowBlank(false);
$validation1->setShowInputMessage(false);
$validation1->setShowErrorMessage(true);
$validation1->setOperator(DataValidation::OPERATOR_EQUAL);
$validation1->setErrorTitle('Error');
$validation1->setError('This cell value must not be changed');
$validation1->setFormula1(77);

$cell2 = $workSheet->getCell('A2');
$cell2->setValue(88);
$validation2 = clone $validation1;
$validation2->setFormula1(88);
$cell2->setDataValidation($validation2);

$writer = new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($spreadsheet);
$writer->save('testFile.xlsx');

Which versions of PhpSpreadsheet and PHP are affected?

Versions after pull request #131

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions