How could you do this in Ms Excel, if you can do it in MS Excel, Aspose.Cells can do this. If you know, kindly create a template file into MS Excel and share it here, we will check it and help you soon.
Also, I think you may try to merge cells for your specific range of cells accordingly, check the topic: