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

Issue with Merging Ranged Sections in PHP Spreadsheet #3894

Open
3 of 11 tasks
sibalonat opened this issue Feb 5, 2024 · 3 comments
Open
3 of 11 tasks

Issue with Merging Ranged Sections in PHP Spreadsheet #3894

sibalonat opened this issue Feb 5, 2024 · 3 comments

Comments

@sibalonat
Copy link

sibalonat commented Feb 5, 2024

This is: [x] a feature request 

Subject:

I'm encountering an issue when attempting to merge ranged sections within PHP Spreadsheet. The current behavior seems to create a visual appearance of merged cells, but the underlying structure doesn't fully merge the cells, leading to potential data integrity and formatting problems.

Steps to Reproduce:

Create a new spreadsheet.

  1. Select a range of cells that you want to merge.

  2. Use the merge method provided by the library (e.g., $spreadsheet->mergeCells('A1:C3')).

  3. Observe that the cells appear merged visually, but their individual properties remain intact.

Expected Behavior:

  • The cells within the specified range should be genuinely merged, resulting in a single cell that spans the entire range.

  • Data and formatting should be consolidated into the merged cell, ensuring consistency and preventing unexpected behavior in subsequent operations.

Actual Behavior:

  • The cells only appear merged visually, but they still function as individual cells in terms of data storage and formatting.

This can lead to issues such as:

  • Data is overwritten when entering values in seemingly merged cells.

  • Formatting inconsistencies when applying styles to the merged range.

Unexpected behavior when performing calculations or data manipulation on the merged cells.

Request:

Please address this issue by implementing a solution that performs a true merge of the selected cells, combining their data and formatting into a single, unified cell. This enhancement would significantly improve the accuracy and reliability of data manipulation within PHPSpreadsheet.

Additional Information:

PHP Spreadsheet library version: 1.29
Operating system: Microsoft
Thank you for your attention to this matter. I'm eager to see this feature implemented to enhance the functionality of PHP Spreadsheet.

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:

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?

Excel and Google Spreadsheet

Which versions of PhpSpreadsheet and PHP are affected?

PHP 8.1
PHPSpreadsheet 1.29

@MarkBaker
Copy link
Member

This isn't quite as straightforward as you think, because while an Excel merge might work in this way, other spreadsheet applications do maintain the old cell values and styles from the other cells in the merged range.
And if you merge cells in an application like Open/LibreOffice and then save that as an Excel file, the old values and styles are still there even in Excel.

The Worksheet's mergeCells() method provides an option for how merging should be handled. By default, this should retain only the value from the top-left cell of the merge range, and set the value of the other cells in the range to null.

@sibalonat
Copy link
Author

sibalonat commented Feb 6, 2024

Yeah, I came across a similar situation, and I wanted to create a pull request with the solution I tried and worked on. The entire implementation by my side also mapped the coordinates, instead, the pull request just copies the range by also grouping them, since in my knowledge when you copy things programmatically, and it passes the threshold of letters, maybe something breaks apart, so to address this, I have applied grouped by. Thank you for the response though, I appreciate it. So far I tried it wit google spreadsheet, i might have also to check these others when I have some time

@sibalonat
Copy link
Author

@MarkBaker take a look maybe at the branch, and let me know if you believe it fits the requirement of what I tried to explain. As mentioned this is grouped by because I thought that it might not be quite the use case when you have copies that span horizontally without a break. So this accommodates this change. I believe this is a good solution. I was first trying another thing, which was more complicated but not very flexible, instead, this is structured well and it almost gives the impression that your copying and pasting

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

No branches or pull requests

2 participants