Search code examples
c#epplus

Centering Across Selection Using EPPlus


If you select adjacent cells in excel and click 'Format Cells', within the alignment tab you can set text alignment to 'Center Across Selection'.

Is there a way to apply this programatically using EPPlus? I searched on their official documentation and couldn't find anything. If there is no way to apply this through EPPlus, what is the best alternative?

The use case is that I need to traverse through cells in one particular row in excel and turn duplicate entries into one entry centered across the cells. The logic I had in mind is to delete the content in all bar the first cell and then center across a selection of all the cells.


Solution

  • EPPlus supports this using CenterContinuous like this:

    ws.Cells[1, 1].Style.HorizontalAlignment = ExcelHorizontalAlignment.CenterContinuous;