PhpSpreadsheet
PhpSpreadsheet copied to clipboard
spreadsheet returns same value for merged cells
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)
I'm getting same value for merged cells. Here A6 & A7 are merged cell. For A6 I'm getting Account Code that is ok but A7 showing same value of A6.
What is the expected behavior?
[ [0] => Account Code [1] => Account Name [2] => For the period [3] => null [4] => null [5] => Cumulative [6] => null [7] => null ] [ [0] => null [1] => null [2] => Debit [3] => Credit [4] => Balance [5] => Debit [6] => Credit [7] => Balance ]
What is the current behavior?
[ [0] => Account Code [1] => Account Name [2] => For the period [3] => For the period [4] => For the period [5] => Cumulative [6] => Cumulative [7] => Cumulative ] [ [0] => Account Code [1] => Account Name [2] => Debit [3] => Credit [4] => Balance [5] => Debit [6] => Credit [7] => Balance ]
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:
try to read excel file which has merged cell.
<?php
require __DIR__ . '/vendor/autoload.php';
// Create new Spreadsheet object
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
$data = $worksheet->rangeToArray(
'A1:H'.$worksheet->getHighestRow('A'),
null,
true,
false,
false
);
// add code that show the issue here...
If this is an issue with reading a specific spreadsheet file, then it may be appropriate to provide a sample file that demonstrates the problem; but please keep it as small as possible, and sanitize any confidential information before uploading.
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?
Which versions of PhpSpreadsheet and PHP are affected?
I'm using 1.28 version and php 8.2
Was this solved?
I don't know. I am unable to replicate the problem:
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->getCell('A1')->setValue('text');
$sheet->mergeCells('A1:B1');
$sheet->getCell('D1')->setValue('=A1');
$sheet->getCell('E1')->setValue('=B1');
var_dump($sheet->rangeToArray('A1:E1', null, true, false, false));
Output:
C:\git\issue.3692a.php:21:
array(1) {
[0] =>
array(5) {
[0] =>
string(4) "text"
[1] =>
NULL
[2] =>
NULL
[3] =>
string(4) "text"
[4] =>
int(0)
}
}
So, B1 is, as expected null. The E1 value of 0 seems a little weird, but it is consistent with Excel's behavior. But there may have been more to the original problem than exists in my code snippet. @saifulferoz, do you have a spreadsheet and/or code that demonstrates (or demonstrated) your problem?
No update in 3 months, closing.