xlwt, Release 1.1.2
A unicode instance is written as is. A bytes instance is converted to unicode us-
ing the encoding, which defaults to ascii, specified when the Workbook instance was
created.
A datetime, date or time instance is converted into Excel date format (a float repre-
senting the number of days since (typically) 1899-12-31T00:00:00, under the pre-
tence that 1900 was a leap year).
A bool instance will show up as TRUE or FALSE in Excel.
None causes the cell to be blank: no data, only formatting.
An xlwt.Formula instance causes an Excel formula to be written.
• style – A style, also known as an XF (extended format), is an XFStyle object, which
encapsulates the formatting applied to the cell and its contents.
XFStyle objects are best set up using the easyxf() function. They may also be set
up by setting attributes in Alignment, Borders, Pattern, Font and Protection
objects then setting those objects and a format string as attributes of an XFStyle object.
1.1 Formatting
The XF record is able to store explicit cell formatting attributes or the attributes of a cell style. Explicit formatting
includes the reference to a cell style XF record. This allows to extend a defined cell style with some explicit attributes.
The formatting attributes are divided into 6 groups:
Group Attributes
Number format Number format index (index to FORMAT record)
Font Font index (index to FONT record)
Alignment Horizontal and vertical alignment, text wrap, indentation, orientation/rotation, text direction
Border Border line styles and colours
Background Background area style and colours
Protection Cell locked, formula hidden
For each group a flag in the cell XF record specifies whether to use the attributes contained in that XF record or in the
referenced style XF record. In style XF records, these flags specify whether the attributes will overwrite explicit cell
formatting when the style is applied to a cell. Changing a cell style (without applying this style to a cell) will change
all cells which already use that style and do not contain explicit cell attributes for the changed style attributes. If a cell
XF record does not contain explicit attributes in a group (if the attribute group flag is not set), it repeats the attributes
of its style XF record.
xlwt.Style.easyxf(strg_to_parse=’‘, num_format_str=None, field_sep=’, ‘, line_sep=’;’, in-
tro_sep=’:’, esc_char=’\\’, debug=False)
This function is used to create and configure XFStyle objects for use with (for example) the
Worksheet.write() method.
It takes a string to be parsed to obtain attribute values for Alignment, Borders, Font, Pattern and
Protection objects.
Refer to the examples in the file examples/xlwt_easyxf_simple_demo.py and to the xf_dict dictionary in
xlwt.Style.
Various synonyms including color/colour, center/centre and gray/grey are allowed. Case is irrelevant (except
maybe in font names). - may be used instead of _.
Example: font: bold on; align: wrap on, vert centre, horiz center
4 Chapter 1. API Reference