PHPOffice / PhpSpreadsheet

A pure PHP library for reading and writing spreadsheet files
https://phpspreadsheet.readthedocs.io
MIT License
13.37k stars 3.47k forks source link

Whe I read a spreadsheet with merged cells, no merged cells found #4191

Open infocube-dev-team opened 1 month ago

infocube-dev-team commented 1 month ago

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?

getMergeCells returns an array with all merged cells in the sheet

What is the current behavior?

getMergeCells returns empty value

What are the steps to reproduce?


<?php

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

// Open Excel file
$spreadSheetFile = "Template.xls"
$reader = IOFactory::createReaderForFile($spreadSheetFile);
$reader->setReadDataOnly(true);
$spreadsheet = $reader->load($spreadSheetFile);

// Get first sheet
$formSheet = $spreadsheet -> getSheet(0);

$merged = $formSheet -> getMergeCells();
if(!empty($merged)) {
    foreach($merged as $merge) {
        var_dump($merge);
    }
}

### What features do you think are causing the issue

- [X] 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?
I don't know.
I tried with the one attached
[Template.xlsx](https://github.com/user-attachments/files/17374218/Template.xlsx)

### Which versions of PhpSpreadsheet and PHP are affected?
PhpSpreadsheet 3.3.0
PHP 8.2
oleibman commented 1 month ago

I believe merge cells are not preserved when you specify ReadDataOnly. Try removing that statement and see what happens.