Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Style for new cell are not compatible with Excel when RowDimension exists and style is null #3534

Closed
1 of 8 tasks
ngyuki opened this issue Apr 23, 2023 · 0 comments · Fixed by #3688
Closed
1 of 8 tasks

Comments

@ngyuki
Copy link

ngyuki commented Apr 23, 2023

This is:

- [x] a bug report
- [ ] a feature request
- [ ] **not** a usage question (ask them on https://stackoverflow.com/questions/tagged/phpspreadsheet or https://gitter.im/PHPOffice/PhpSpreadsheet)

What is the expected behavior?

When RowDimension exists but its style is null, prefer column style to row style.

What is the current behavior?

When RowDimension exists, its style prefer column style, even if the style is null.

What are the steps to reproduce?

  1. Apply background color to entire Column A:A in Excel (Create columnDimension(A) and apply style)
  2. Changes the height of row 1:1 in Excel (Create rowDimension(1))
  3. Execute the following code to change value of cell A1 and save it
  4. In the saved xlsx file, the background color of cell A1 is cleared
<?php

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

use PhpOffice\PhpSpreadsheet\IOFactory;
$book = IOFactory::load(__DIR__ . '/input.xlsx');
$sheet = $book->getSheet(0);

var_dump($sheet->getCellCollection()->getCoordinates()); // []
var_dump($sheet->getColumnDimension('A')->getXfIndex()); // int(1)
var_dump($sheet->getRowDimension(1)->getXfIndex());      // NULL

$sheet->getCell('A1')->setValue('x');

var_dump($sheet->getCellCollection()->getCoordinates()); // ['A1']
var_dump($sheet->getCell('A1')->getXfIndex());           // int(0)

IOFactory::createWriter($book, IOFactory::READER_XLSX)->save(__DIR__ . '/output.xlsx');

input.xlsx
output.xlsx

What features do you think are causing the issue

  • Reader
  • Writer
  • Styles
  • Data Validations
  • Formula Calculations
  • Charts
  • AutoFilter
  • Form Elements

Does an issue affect all spreadsheet file formats? If not, which formats are affected?

XLSX (as far as I know)

Which versions of PhpSpreadsheet and PHP are affected?

php 8.2.2
phpoffice/phpspreadsheet 1.28.0 and master(e9cf273)

oleibman added a commit to oleibman/PhpSpreadsheet that referenced this issue Aug 28, 2023
Fix PHPOffice#3534. For new cells, style is set to Row Dimension Style when Row Dimension exists (even if Row Dimension Style does not exist), else Column Dimension Style when Column Dimension exists. However it should be set to Row Dimension Style when Row Dimension exists *and* Row Dimension Style exists, else ...
oleibman added a commit that referenced this issue Sep 3, 2023
* Use Column Style When Row Dimension Exists Without Style

Fix #3534. For new cells, style is set to Row Dimension Style when Row Dimension exists (even if Row Dimension Style does not exist), else Column Dimension Style when Column Dimension exists. However it should be set to Row Dimension Style when Row Dimension exists *and* Row Dimension Style exists, else ...

* Address Issue 3533

If cell is defined in xml, it uses neither row nor column style. If style is omitted in cell definition, default style is used.

* Update CHANGELOG.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

1 participant