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 set it true, changes in alignment will take place; otherwise, they will not. Please note that the StyleFlag object is passed as a parameter to the 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 while keeping the existing formatting intact. The following screenshot compares the sample Excel file and the output Excel file and shows that all existing formatting of the cells is the same, except that the cells are now center‑aligned horizontally and vertically.

todo:image_alt_text

Sample Code