PyXLL The Python Excel Add-In
  • Product
    • Features
    • Get Started
    • Request Demo
    • Download
  • Pricing
  • Resources
    • Documentation
    • Blog
    • Videos
    • FAQ
    • Learn Python
    • Customer Portal
    • About Us
  • Support
    • Documentation
    • Videos
    • FAQ
    • Contact Us
  • Contact Us
Table of Contents
  • PyXLL Documentation
  • Introduction to PyXLL
  • User Guide
    • Installing PyXLL
    • Configuring PyXLL
    • Worksheet Functions
    • Macro Functions
    • Real Time Data
    • Cell Formatting
      • Formatting Worksheet Functions
      • Pandas DataFrame Formatting
      • Custom Formatters
      • Formatting in Macros Functions
    • Charts and Plotting
    • Custom Task Panes
    • ActiveX Controls
    • Using Pandas in Excel
    • Customizing the Ribbon
    • Context Menu Functions
    • Working with Tables
    • Python as a VBA Replacement
    • Menu Functions
    • Reloading and Rebinding
    • Error Handling
    • Deploying your add-in
    • Workbook Metadata
  • Video Guides and Tutorials
  • API Reference
  • What’s new in PyXLL 5
  • Changelog
Close

Formatting Worksheet Functions¶

Worksheet functions registered using xl_func can format their results using a Formatter.

To specify what formatter should be used for a function use the formatter kwarg to the xl_func decorator. For example:

from pyxll import xl_func, Formatter
import datetime as dt

date_formatter = Formatter(number_format="yyyy-mm-dd")

@xl_func(formatter=date_formatter)
def get_date():
    return dt.date.today()

When the function is called from Excel, any previous formatting is cleared and the formatter is applied to the cell.

The standard Formatter handles many common formatting requirements and takes the following options:

Formatter kwargs

interior_color

Color value to set the interior color to.

text_color

Color value to set the text color to.

bold

If True, set the text style to bold.

italic

If True, set the text style to italic.

font_size

Value to set the font size to.

number_format

Excel number format to use.

auto_fit

Auto-fit to the content of the cells.

May be any of: True (fit column width); False (don’t fit); “columns” (fit column width); “rows” (fit row width); “both” (fit column and row width);

Color values can be obtained using the static method Formatter.rgb.

More complex formatting can be done using a custom formatter.

The Formatter clears all formatting before applying the new formatting, but you can also control how the formatting is cleared using a custom formatter.

Note

When formatting is applied to Dynamic Array functions PyXLL will keep track of the current array size and save it in the Workbook Metadata.

This is so the previous range can be cleared before re-applying formatting. Without doing this the formatting would remain if the array contracted.

« Cell Formatting
Pandas DataFrame Formatting »
  • Home
  • Product
  • Features
  • Documentation
  • Download
  • Pricing
  • Support
  • Documentation
  • Videos
  • FAQ
  • Learn Python
  • Contact Us
  • About
  • About Us
  • Legal
  • Blog
© Copyright PyXLL Ltd