Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 

README.md

How to Configure Cell Border and Text Alignment

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.

Getting Started with IronXL


Example: Setting Cell Border and Alignment

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");
Border And Alignment Configuration

Advanced Cell Border and Alignment Customization

Border Color Customization

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");
Custom Border Color

Border Lines and Patterns

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");

Displaying Border Lines

Border Line Types

Showcasing Border Patterns

Border Patterns Example

Illustration of Alignment Types Offered by IronXL

Get to know the extensive alignment functionalities provided by IronXL through this graphical representation:

Alignment Types Example