IronSoftware
  • Products
    Create, read, and edit PDFs Image to text in 127 languages Read and write QR & Barcodes No Office Interop required Extract structured data from websites 5 for the Price of 2 All 5 .NET product licenses from $998 Save 60% with Iron Suite Iron Suites - Donate $50
  • About Us
  • Contact Us

205 N. Michigan Ave. Chicago, IL 60611, USA +1 (312) 500-3060

  • Home
  • Licensing
  • EULA
  • Support & Update Extensions
  • Get Started
  • Features
  • Code Examples
  • Tutorials
  • FAQ
  • Troubleshooting
  • API Reference
  • Search
  • Free NuGet Download
IronXL - Excel Library for C# .Net IronXL - Excel Library for C# .Net
  • Home
  • Licensing
    • Licensing
    • EULA
    • Support & Update Extensions
  • Docs
    • Search
    • Get Started
    • Features
    • Code Examples
    • Tutorials
    • FAQ
    • Troubleshooting
    • API Reference
    • Search
  • Search
  • Free NuGet Download Total downloads: 179,360
Message's icon
IronXL
Code Examples
  1. IronXL
  2. Code Examples
  3. Style Excel Cell Borders & Fonts
IronXL
Free for development from NuGet

Install with NuGet nuget.org/packages/IronXL.Excel

PM > Install-Package IronXL.Excel

Explore the Docs

  • Get Started
  • Features
  • Code Examples
    • How to Read an Excel File in C#
    • Using C# to Create Excel Files in .Net
    • Use C# to Open & Write an Excel File
    • License Keys
    • Create an XLSX File
    • Work with Excel in .NET Core
    • Export to Excel in C#
    • Read XLSX File C#
    • Work with Excel in C# without Interop
    • Write Excel Values in .NET
    • Open Excel Worksheets in C#
    • Parse Excel Files in C#
    • Read Excel File Example
    • Work with VB .NET Excel Files
    • Add Rows & Columns in Excel C# Docs
    • Import Excel Data in C#
    • Generate Excel Files in C#
    • Create Excel Documents in C#
    • Edit Excel Files in C#
    • Merge Cells in Excel C# Documents
    • Create Excel Charts in C#
    • Read a CSV in C#
    • Write CSV in .NET
    • Use a CSV parser in C#
    • Create a CSV file using C#
    • Convert a Data Table to CSV
    • Convert XLSX to CSV, JSON, XML
    • Setup on macOS
    • Setup on AWS
    • Setup on Azure
    • Setup on Docker
    • Setup on Linux
    • Troubleshooting Guides
      • Apply a license key in IronXL
      • File Size Limits
    • Product Release Notes
      • IronXL v2021.11.0
      • IronXL v2021.12.0
      • IronXL v2022.3.0
      • IronXL v2022.6.6825
  • API Reference
Read Excel Files without Interop
Excel Worksheets
Excel Range Cells
Create a new Excel File
Convert Spreadsheet File Types
Excel to SQL via System.Data.DataSet
Excel to SQL and DataGrid via DataTable
Excel Conditional Formatting
Convert XLS to XLSX in C#
Protect Excel Files
Excel Formulas in C#
Save Excel to Database
Edit Excel Metadata in C#
Update Excel Database Records
Style Excel Cell Borders & Fonts
Sort Excel Ranges in C#
Repeat Excel Rows & Columns
Read XLSX Files
Excel Print Setup
Preserve Excel Macros in XLSM
Excel Number Format
Load Excel From SQL Database
Combine Excel Ranges
Select Excel Range
Generate Excel Files
XLSX to XLSM with Macros
Convert Excel to HTML
Import Export Excel
Aggregate Excel Functions
CSV to Excel
Create Excel Scatter Chart
Create Excel Line Chart
Create Excel Bar Chart
Freeze Panes in Excel
Create Excel Worksheet
Copy Excel Worksheets

Style Excel Cell Borders & Fonts

using System.Linq;
using IronXL;
using IronXL.Styles;

WorkBook workbook = WorkBook.Load("test.xls");
WorkSheet sheet = workbook.WorkSheets.First();
var range = sheet["A1:H10"];

var cell = range.First();

//This is how we set background color of the cell with an rgb string
cell.Style.SetBackgroundColor("#428D65");

//Styling can be applied to the whole range.

//This is how we set underline property to the font
//FontUnderlineType is enum that stands for different types of font underlying
range.Style.Font.Underline = FontUnderlineType.SingleAccounting;

//This is how we define whether to use horizontal line through the text or not
range.Style.Font.Strikeout = false;

//This is how we define whether the font is bold or not
range.Style.Font.Bold = true;

//This is how we define whether the font is italic or not
range.Style.Font.Italic = false;

//This is how we can get or set script property of a font
//Font script enum stands for available options
range.Style.Font.FontScript = FontScript.Super;

//This is how we can set  the type of the border line
//There are also TopBorder,LeftBorder,RightBorder,DiagonalBorder properties
//BorderType enum indicates the line style of a border in a cell
range.Style.BottomBorder.Type = BorderType.MediumDashed;

//This is how we can indicate whether the cell should be auto-sized 
range.Style.ShrinkToFit = true;

//This is how we can set alignment of the cell
range.Style.VerticalAlignment = VerticalAlignment.Bottom;

//This is how we can set border color
range.Style.DiagonalBorder.SetColor("#20C96F");

//We need to define border type and border direction as well
range.Style.DiagonalBorder.Type = BorderType.Thick;

//DiagonalBorderDirection enum stands for direction of diagonal border inside cell
range.Style.DiagonalBorderDirection = DiagonalBorderDirection.Forward;

//Set background color of cells
range.Style.SetBackgroundColor(Color.Aquamarine);

//This is how we can set fill pattern of the cell
//FillPattern enum indicates the style of fill pattern
range.Style.FillPattern = FillPattern.Diamonds;

//This is how we can set the number of spaces to intend the text
range.Style.Indention = 5;

//This is how we can indicate if the text is wrapped
range.Style.WrapText = true;

workbook.SaveAs("StylingOptions.xls");
Imports System.Linq
Imports IronXL
Imports IronXL.Styles

Private workbook As WorkBook = WorkBook.Load("test.xls")
Private sheet As WorkSheet = workbook.WorkSheets.First()
Private range = sheet("A1:H10")

Private cell = range.First()

'This is how we set background color of the cell with an rgb string
cell.Style.SetBackgroundColor("#428D65")

'Styling can be applied to the whole range.

'This is how we set underline property to the font
'FontUnderlineType is enum that stands for different types of font underlying
range.Style.Font.Underline = FontUnderlineType.SingleAccounting

'This is how we define whether to use horizontal line through the text or not
range.Style.Font.Strikeout = False

'This is how we define whether the font is bold or not
range.Style.Font.Bold = True

'This is how we define whether the font is italic or not
range.Style.Font.Italic = False

'This is how we can get or set script property of a font
'Font script enum stands for available options
range.Style.Font.FontScript = FontScript.Super

'This is how we can set  the type of the border line
'There are also TopBorder,LeftBorder,RightBorder,DiagonalBorder properties
'BorderType enum indicates the line style of a border in a cell
range.Style.BottomBorder.Type = BorderType.MediumDashed

'This is how we can indicate whether the cell should be auto-sized 
range.Style.ShrinkToFit = True

'This is how we can set alignment of the cell
range.Style.VerticalAlignment = VerticalAlignment.Bottom

'This is how we can set border color
range.Style.DiagonalBorder.SetColor("#20C96F")

'We need to define border type and border direction as well
range.Style.DiagonalBorder.Type = BorderType.Thick

'DiagonalBorderDirection enum stands for direction of diagonal border inside cell
range.Style.DiagonalBorderDirection = DiagonalBorderDirection.Forward

'Set background color of cells
range.Style.SetBackgroundColor(Color.Aquamarine)

'This is how we can set fill pattern of the cell
'FillPattern enum indicates the style of fill pattern
range.Style.FillPattern = FillPattern.Diamonds

'This is how we can set the number of spaces to intend the text
range.Style.Indention = 5

'This is how we can indicate if the text is wrapped
range.Style.WrapText = True

workbook.SaveAs("StylingOptions.xls")
Read more
Install-Package IronXL.Excel

Style Excel Cell Borders & Fonts

IronXL allows c# developers to style any Excel `Cell` and `Range` in C#. For example it is easy to control: borders, colors, backgrounds and fonts.

You can download the software product from this link.

Previous Example
Next Example

Ready to get started? Version: 2022.6 just released

Free NuGet Download Total downloads: 179,360 View Licenses >
Try IronXL for Free
Get Set Up in 5 Minutes
C# Nuget Library for PDF
Install with NuGet
Version: 2022.6
Install-Package IronXL.Excel
nuget.org/packages/IronXL.Excel/
  1. In Solution Explorer, right-click References, Manage NuGet Packages
  2. Select Browse and search "IronXL"
  3. Select the package and install
C# PDF DLL
Download DLL
Version: 2022.6
Download Now
Manually install into your project
  1. Download and unzip IronXL to a location such as ~/Libs within your Solution directory
  2. In Visual Studio Solution Explorer, right click References. Select Browse, "IronXL.dll"
Licenses from $499

Have a question? Get in touch with our development team.

Now that you’ve downloaded IronXL
Want to deploy IronXL to a live project for FREE?
Not ready to buy?

Want to deploy IronXL to a live project for FREE?

What’s included?
30 days of fully-functional product
Test and share in a live environment
No restrictions in production
Get your free 30-day Trial Key instantly.
Thank you.
If you'd like to speak to our licensing team:
Schedule a call
Have a question? Get in touch with our development team.
No credit card or account creation required
Your Trial License Key has been emailed to you.
Not ready to buy?
Thank you.
View your license options:
Thank you.
If you'd like to speak to our licensing team:
View License
Schedule a call
Have a question? Get in touch with our development team.
Have a question? Get in touch with our development team.
Want to deploy IronXL to a live project for FREE?
Not ready to buy?

Want to deploy IronXL to a live project for FREE?

What’s included?
30 days of fully-functional product
Test and share in a live environment
No restrictions in production
Get your free 30-day Trial Key instantly.
Thank you.
If you'd like to speak to our licensing team:
Schedule a call
Have a question? Get in touch with our development team.
No credit card or account creation required
Your Trial License Key has been emailed to you.
Not ready to buy?
Download IronXL free to apply
your Trial Licenses Key
Thank you.
If you'd like to speak to our licensing team:
Install with NuGet View Licenses
Schedule a call
Licenses from $499. Have a question? Get in touch.
Have a question? Get in touch with our development team.
Free 30-Day Trial Key

Fully-functional product, get the key instantly

IronXL for .NET

The Excel API you need, without the Office Interop hassle.

Search

Documentation

  • Code Examples
  • API Reference
  • FAQ
  • Features
  • Blog
  • Credits
  • Product Brochure

Tutorials

  • Get Started
  • Read an Excel File in C#
  • Create Excel Files in .Net

Licensing

  • Buy a License
  • Support Extensions
  • Resellers
  • License Keys
  • EULA

Try IronXL Free

  • Download on NuGet
  • Download DLL
  • 30-Day Trial License

When you need your PDF to look like HTML, fast.

Tesseract 5 OCR in the languages you need, We support 127+.

When you need to read, write, and style, QR & Barcodes, fast.

The Excel API you need, without the Office Interop hassle.

The power you need to scrape & output clean, structured data.

The complete .NET Suite for your office.

  • IRONSUITE
  • |
  • IRONPDF
  • IRONOCR
  • IRONBARCODE
  • IRONXL
  • IRONWEBSCRAPER
IronSoftware
205 N. Michigan Ave. Chicago, IL 60611 USA +1 (312) 500-3060
  • About Us
  • Contact Us

Supporting Teamseas

Copyright © Iron Software LLC 2013-2022

  • Terms
  • Privacy

Thank you!

Your license key has been delivered to the email provided. Contact us

48-Hour Upgrade Offer:

Save 50% on a
Professional Upgrade

Go Professional to cover 10 developers
and unlimited projects.

Upgrade to Professional

Upgrade

Professional

$600 USD

$299 USD


  • 10 developers
  • 10 locations
  • 10 projects