Based on https://ironsoftware.com/how-to/border-alignment/
Cell borders in Excel are the distinct lines that can be added around cells or groups of cells. Text alignment, conversely, determines the placement of text within a cell both on the vertical and horizontal axes.
Utilizing IronXL, you can elevate data visualization, augment readability, and forge spreadsheets that look and feel professional by personalizing border styles, thickness, colors, and text alignments for enhanced data representation.
Modify the visual style of a specific cell, column, row, or block of cells by applying borders through the TopBorder, RightBorder, BottomBorder, and LeftBorder properties. IronXL offers various border styles through the IronXL.Styles.BorderType enumeration. Explore all possible border styles to select the ideal one for your needs.
For precise control over text positioning, tweak the HorizontalAlignment and VerticalAlignment properties in the Style object according to your requirements. Use the enumerations IronXL.Styles.HorizontalAlignment and IronXL.Styles.VerticalAlignment for setting desired text orientations. Discover all alignment options to perfectly present your data.
using IronXL;
using IronXL.Styles;
WorkBook workBook = WorkBook.Create();
WorkSheet workSheet = workBook.DefaultWorkSheet;
workSheet["B2"].Value = "Cell B2";
// Apply cell border
workSheet["B2"].Style.LeftBorder.Type = BorderType.MediumDashed;
workSheet["B2"].Style.RightBorder.Type = BorderType.MediumDashed;
// Adjust text alignment
workSheet["B2"].Style.HorizontalAlignment = HorizontalAlignment.Center;
workBook.SaveAs("customizedBorderAndAlignment.xlsx");While the default color for borders is black, IronXL enables customization to any preferable color using the Color class or Hex color codes. Set the border color via the Color property by specifying your desired color or Hex code. Remember, the border color remains invisible until a border type is specified.
using IronXL;
using IronXL.Styles;
using IronSoftware.Drawing;
WorkBook workBook = WorkBook.Create();
WorkSheet workSheet = workBook.DefaultWorkSheet;
workSheet["B2"].Style.LeftBorder.Type = BorderType.Thick;
workSheet["B2"].Style.RightBorder.Type = BorderType.Thick;
// Customize border color
workSheet["B2"].Style.LeftBorder.SetColor(Color.Aquamarine);
workSheet["B2"].Style.RightBorder.SetColor("#FF7F50");
workBook.SaveAs("customBorderColors.xlsx");IronXL supports six border line positions with multiple patterns or types including top, right, bottom, left, diagonal forward, diagonal backward, and diagonal in both directions.
using IronXL;
using IronXL.Styles;
WorkBook workBook = WorkBook.Create();
WorkSheet workSheet = workBook.DefaultWorkSheet;
workSheet["B2"].StringValue = "Set Top Border";
workSheet["B4"].StringValue = "Set Diagonal Forward Border";
// Apply top border
workSheet["B2"].Style.TopBorder.Type = BorderType.Thick;
// Apply diagonal border and set direction
workSheet["B4"].Style.DiagonalBorder.Type = BorderType.Thick;
workSheet["B4"].Style.DiagonalBorderDirection = DiagonalBorderDirection.Forward;
workBook.SaveAs("differentBorderTypes.xlsx");Get to know the extensive alignment functionalities provided by IronXL through this graphical representation:




