IRONSOFTWAREHOME
Excel-Zellränder und Schriftarten stylen
from ironxl import *

# Load existing spreadsheet
workbook = WorkBook.Load("sample.xls")
worksheet = workbook.WorkSheets[0]

# Get a range from an Excel worksheet
selected_range = worksheet["A1:H10"]

# Get the first cell in the range
cell = selected_range.ToArray()[0]

# Set background color of the cell with an RGB string
cell.Style.SetBackgroundColor("#428D65")

# Apply styling to the whole range

# Set underline property to the font
# FontUnderlineType is an enum that stands for different types of font underline
selected_range.Style.Font.Underline = FontUnderlineType.SingleAccounting

# Define whether to use a horizontal line through the text or not
selected_range.Style.Font.Strikeout = False

# Define whether the font is bold or not
selected_range.Style.Font.Bold = True

# Define whether the font is italic or not
selected_range.Style.Font.Italic = False

# Get or set the script property of a font
# FontScript enum stands for available options
selected_range.Style.Font.FontScript = FontScript.Super

# 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
selected_range.Style.BottomBorder.Type = BorderType.MediumDashed

# Indicate whether the cell should be auto-sized
selected_range.Style.ShrinkToFit = True

# Set alignment of the cell
selected_range.Style.VerticalAlignment = VerticalAlignment.Bottom

# Set border color
selected_range.Style.DiagonalBorder.SetColor("#20C96F")

# Define border type and border direction as well
selected_range.Style.DiagonalBorder.Type = BorderType.Thick

# DiagonalBorderDirection enum stands for direction of diagonal border inside cell
selected_range.Style.DiagonalBorderDirection = DiagonalBorderDirection.Forward

# Set background color of cells
selected_range.Style.SetBackgroundColor(Color.Aquamarine)

# Set fill pattern of the cell
# FillPattern enum indicates the style of fill pattern
selected_range.Style.FillPattern = FillPattern.Diamonds

# Set the number of spaces to indent the text
selected_range.Style.Indention = 5

# Indicate if the text is wrapped
selected_range.Style.WrapText = True

# Save changes with applied styling options
workbook.SaveAs("stylingOptions.xls")
pip install ironxl
Excel-Zellränder und Schriftarten stylen

Excel-Zellränder und Schriftarten stylen

IronXL for Python ermöglicht es Entwicklern, beliebige Excel-Cell oder Range zu gestalten. IronXL deckt die meisten Styling-Optionen von Microsoft Excel ab, einschließlich Schriftarten, Textausrichtung, Rahmen, Farben, Hintergründe und Füllmuster. Das folgende Codebeispiel zeigt eine breite Palette von Stilen, die mit IronXL konfiguriert werden können.

Einzelne Zell- und Bereichsrahmen (unten, oben, links, rechts und diagonal) können auf 14 verschiedene Rahmenstile wie gepunktet, gestrichelt und doppelt gesetzt werden, indem das BorderType-Enum verwendet wird. Die Eigenschaften ShrinkToFit und WrapText bieten zusätzliche Kontrolle darüber, wie das Tabellenkalkulationsprogramm Zellinhalte und -größen verwaltet.

Lernen Sie, wie man die Schriftgröße einer Excel-Zelle in Python anpasst.

Bereit anzufangen?

Version:2026.9gerade veröffentlicht

Key in blue circle

Holen Sie sich sofort Ihren kostenlosen 30-Tage-Testschlüssel.

Your trial license will be sent to your email address

Keine Einschränkungen. 100 % freigeschaltet. Keine Kreditkarte.

bullet_checkedIhr Testlizenzschlüssel wurde Ihnen per E-Mail gesendet.Keine Einschränkungen. 100 % freigeschaltet. Keine Kreditkarte.
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried IronPDF
AWS-Logo
Booking Badge

Von Millionen von Ingenieur*innen weltweit vertraut

Azure (WebApps, Funktionen v3)
Erhalten Sie Ihre unverbindliche Beratung
Füllen Sie das Formular unten aus oder senden Sie eine E-Mail an sales@ironsoftware.com
Ihre Daten werden immer vertraulich behandelt.
Von Millionen von Ingenieur*innen weltweit vertraut
Azure (WebApps, Funktionen v3)
Erhalten Sie sofort Ihren kostenlosen 30-Tage-Testschlüssel.
Ihr Testlizenzschlüssel wurde Ihnen per E-Mail gesendet.