PhpSpreadsheet
PhpSpreadsheet copied to clipboard
Whe I read a spreadsheet with merged cells, no merged cells found
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
I believe merge cells are not preserved when you specify ReadDataOnly. Try removing that statement and see what happens.
I think i see the same problem. I read data from an xlsx file. After outputting it as html the merged cells are not merged anymore, they are unmerged.
It looks okay when I load an xlsx spreadsheet with merged cells and save it as html. Are you sure you are not specifying readDataOnly? If you are sure, I need you to upload code and/or spreadsheet which demonstrates the problem.
After saving the .xlsx file with libre office the merged cells are there. Currently i dont know which Version of Excel was used to save it.
No recent update, unable to reproduce, closing.
The Excelversion used to save the nonworking File: Microsoft Office LTSC Professional-Plus 2021 Version 2108, Build 14332.20857 Microsoft Excel LTSC MSO, 16.0.14332.20848, 64bit
If you want to upload the non-working file, I will see if I can reproduce your problem. So far, I can't.