D
D
Dmitry Luzin2017-05-04 11:45:31
PHP
Dmitry Luzin, 2017-05-04 11:45:31

PHPExcel how to insert an array via fromArray if template has merged cells?

There is a template in which some cells are merged. The script generates data and writes to the template. The problem with merged cells, when you insert an array, the data is written to the cells that are included in the merger and, accordingly, all this is displayed crookedly. How to skip such cells?
It is not known in advance which are combined and which are not (by rows or columns). The output of the block starts from the given coordinates.
Example:
....

$arr=[1,2,3,4,5,6,7,8,9,10];
$sheet->fromArray($arr, null, 'A1');

...
Assume A2,A3,A4 are merged. The output will be
1 | 2 | 5 | 6 | 7 | 8 | 9 | 10
3.4 - fall out.
Any solutions?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Khodyrev, 2017-05-04
@maximkou

Write your own implementation of filling cells from an array based on the original - https://github.com/PHPOffice/PHPExcel/blob/1c8c237...
When filling, check if the cell is included in the merged list. If it enters, you skip it, except for the boundary cell.
An example of checking a cell for merging: stackoverflow.com/a/7299859/1559720

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question