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

removeRow #2442

Closed
toboul70 opened this issue Dec 9, 2021 · 3 comments · Fixed by #2486
Closed

removeRow #2442

toboul70 opened this issue Dec 9, 2021 · 3 comments · Fixed by #2486

Comments

@toboul70
Copy link

toboul70 commented Dec 9, 2021

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?

remove Row and keep style of other cells

What is the current behavior?

remove Row and keep style of removed Row.

Before removeRow
1

After removeRow (row 4)
2

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';

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

$excel  = new PhpOffice\PhpSpreadsheet\Spreadsheet();
$excel  = PhpOffice\PhpSpreadsheet\IOFactory::load($file);
$org    = $excel->getSheetByName('Feuil1');

$org->removeRow(4, 1);

$writer = PhpOffice\PhpSpreadsheet\IOFactory::createWriter($excel, 'Xlsx');
$writer->setPreCalculateFormulas(false);
$writer->save($filemodified);

?>

Which versions of PhpSpreadsheet and PHP are affected?

PHP 7.3.21 (cli) (built: Aug 4 2020 11:21:19) ( ZTS MSVC15 (Visual C++ 2017) x64 )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.21, Copyright (c) 1998-2018 Zend Technologies

"name": "phpoffice/phpspreadsheet",
"version": "1.20.0",
"source": {
"type": "git",
"url": "https://github.com/PHPOffice/PhpSpreadsheet.git",
"reference": "44436f270bb134b4a94670f3d020a85dfa0a3c02"

@MarkBaker
Copy link
Member

Why wold you expect that behaviour? Like the content, the styling of the cells in a row is removed when those cells are removed; shuffling all subsequent rows up. And this is exactly the behaviour that MS Excel demonstrates when you remove a row.

@toboul70
Copy link
Author

toboul70 commented Jan 1, 2022

I expect that the height of the "new line 4" would be the same as "the old line 5".
In my example, it's not the case.

@MarkBaker
Copy link
Member

Ah! Now I understand. Yes, that looks like a bug, we should also adjust the row heights (and column widths when removing a column as well). Row height isn't maintained as an aspect of cell style; but as an aspect of the worksheet.

oleibman pushed a commit to oleibman/PhpSpreadsheet that referenced this issue Jan 4, 2022
Fix PHPOffice#2442. Although data and styles are handled correctly after removing row(s) or column(s), the dimensions of the removed rows and columns remain behind to afflict their replacements. This PR will take care of removing the dimensions as well.

Dimensions has a _clone method for a deep clone, but all of its properties, as well as the properties of RowDimensions and ColumnDimensions, are scalars, and do not require a deep clone. The method is deleted.
oleibman added a commit that referenced this issue Jan 14, 2022
Fix #2442. Although data and styles are handled correctly after removing row(s) or column(s), the dimensions of the removed rows and columns remain behind to afflict their replacements. This PR will take care of removing the dimensions as well.

Dimensions has a _clone method for a deep clone, but all of its properties, as well as the properties of RowDimensions and ColumnDimensions, are scalars, and do not require a deep clone. The method is deleted.
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.

2 participants