Skip to content
Advertisement

How to read a excel file with merged cells in php?

I wrote a php script that allows me to read an uploaded excel file and insert all the images contained in a folder by renaming them with the cell values “style” and “color” to have style_color.jpg. The script works fine but if I upload an xlsx file containing merged cells like this:

enter image description here

images with the same “style” doesn’t work.The tool will just put the style on the first image. I would like the first two images to be called :

JavaScript

How can I read these merged cells?

JavaScript

Advertisement

Answer

If you can assume that you read the rows in sequence, you can get the cell value and if the cell is blank, use the previous value. This code use ?: to say if it’s blank, use $stylecode

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement