Looping logic when adding new rows in PHPExcel

I have a problem about adding new rows using PHPExcel. In my data I have a multidimensional array. And I don't know how can I add a new rows below the newly inserted row. Here's the sample data of my array I removes some of the details to make it short:

You are handling the row indexes incorrectly in your loops and that results your code to write several times to same rows. You need a generic row counter to get the row numbers correctly in place, i.e. something like this (I removed the removeRow calls as I didn't quite understand what you were trying to achieve with those):