xlwt.Workbook.
Workbook
(
encoding='ascii'
,
style_compression=0
)
¶
This is a class representing a workbook and all its contents. When creating Excel files with xlwt, you will normally start by instantiating an object of this class.
add_sheet
(
sheetname
,
cell_overwrite_ok=False
)
¶
This method is used to create Worksheets in a Workbook.
| 参数: |
|
|---|---|
| 返回: |
The
|
save
(
filename_or_stream
)
¶
This method is used to save the Workbook to a file in native Excel format.
| 参数: |
filename_or_stream
– This can be a string containing a filename of
the file, in which case the excel file is saved to disk using the name
provided. It can also be a stream object with a write method, such as
a
StringIO
, in which case the data for the excel
file is written to the stream.
|
|---|
xlwt.Worksheet.
Worksheet
(
sheetname
,
parent_book
,
cell_overwrite_ok=False
)
¶
This is a class representing the contents of a sheet in a workbook.
警告
You don’t normally create instances of this class yourself. They are returned from calls to
add_sheet()
.
write
(
r
,
c
,
label=''
,
style=<xlwt.Style.XFStyle object>
)
¶
This method is used to write a cell to a
Worksheet
.
| 参数: |
|
|---|
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 | 属性 |
|---|---|
| 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 |
| 保护 | 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.
EasyXFAuthorError
¶
xlwt.Style.
EasyXFCallerError
¶
xlwt.Style.
EasyXFException
¶
xlwt.Style.
easyxf
(
strg_to_parse=''
,
num_format_str=None
,
field_sep='
,
'
,
line_sep=';'
,
intro_sep=':'
,
esc_char='\\'
,
debug=False
)
¶
This function is used to create and configure
XFStyle
objects for use with (for example) the
Worksheet.write()
方法。
It takes a string to be parsed to obtain attribute values for
Alignment
,
Borders
,
Font
,
Pattern
and
保护
对象。
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
_
.
范例:
font:
bold
on;
align:
wrap
on,
vert
centre,
horiz
center
| 参数: |
num_format_str
–
To get the “number format string” of an existing cell whose format you want to reproduce, select the cell and click on Format/Cells/Number/Custom. Otherwise, refer to Excel help.
范例:
|
|---|---|
| 返回: |
An
XFstyle
对象。
|