Change Cells Alignment and Keep Existing Formatting

Possible Usage Scenarios

Sometimes, you want to change the alignment of multiple cells but also want to keep existing formatting. Aspose.Cells allows you to do it using the StyleFlag.Alignments property. If you will set it true, changes in alignment will take place otherwise not. Please note, StyleFlag object is passed as a parameter to Range.ApplyStyle() method which actually applies the formatting to a range of cells.

Change Cells Alignment and Keep Existing Formatting

The following sample code loads the sample Excel file, creates the range and center aligns it horizontally and vertically and keeps the existing formatting intact. The following screenshot compares the sample Excel file and output Excel file and shows that all existing formatting of the cells is the same except that cells are now center aligned horizontally and vertically.

todo:image_alt_text

Sample Code