Worksheet is the 2nd-level container in Excel.
openpyxl.worksheet.worksheet.
Worksheet
(
parent
,
title=None
)
[source]
¶
Bases:
openpyxl.workbook.child._WorkbookChild
Represents a worksheet.
Do not create worksheets yourself, use
openpyxl.workbook.Workbook.create_sheet()
代替
BREAK_COLUMN
= 2
¶
BREAK_NONE
= 0
¶
BREAK_ROW
= 1
¶
ORIENTATION_LANDSCAPE
= 'landscape'
¶
ORIENTATION_PORTRAIT
= 'portrait'
¶
PAPERSIZE_A3
= '8'
¶
PAPERSIZE_A4
= '9'
¶
PAPERSIZE_A4_SMALL
= '10'
¶
PAPERSIZE_A5
= '11'
¶
PAPERSIZE_EXECUTIVE
= '7'
¶
PAPERSIZE_LEDGER
= '4'
¶
PAPERSIZE_LEGAL
= '5'
¶
PAPERSIZE_LETTER
= '1'
¶
PAPERSIZE_LETTER_SMALL
= '2'
¶
PAPERSIZE_STATEMENT
= '6'
¶
PAPERSIZE_TABLOID
= '3'
¶
SHEETSTATE_HIDDEN
= 'hidden'
¶
SHEETSTATE_VERYHIDDEN
= 'veryHidden'
¶
SHEETSTATE_VISIBLE
= 'visible'
¶
active_cell
¶
add_chart
(
chart
,
anchor=None
)
[source]
¶
Add a chart to the sheet Optionally provide a cell for the top-left anchor
add_data_validation
(
data_validation
)
[source]
¶
Add a data-validation object to the sheet. The data-validation object defines the type of data-validation to be applied and the cell or range of cells it should apply to.
add_image
(
img
,
anchor=None
)
[source]
¶
Add an image to the sheet. Optionally provide a cell for the top-left anchor
add_table
(
table
)
[source]
¶
Check for duplicate name in definedNames and other worksheet tables before adding table.
append
(
iterable
)
[source]
¶
Appends a group of values at the bottom of the current sheet.
| 参数: | iterable ( list|tuple|range|generator or dict ) – list, range or generator, or dict containing values to append |
|---|
用法:
| Raise: | TypeError when iterable is neither a list/tuple nor a dict |
|---|
calculate_dimension
(
)
[source]
¶
Return the minimum bounding range for all cells containing data (ex. ‘A1:M24’)
| 返回类型: | string |
|---|
cell
(
row
,
column
,
value=None
)
[source]
¶
Returns a cell object based on the given coordinates.
Usage: cell(row=15, column=1, value=5)
调用 cell creates cells in memory when they are first accessed.
| 参数: |
|
|---|---|
| 返回类型: | openpyxl.cell.cell.Cell |
columns
¶
Produces all cells in the worksheet, by column (see
iter_cols()
)
dimensions
¶
Returns the result of
calculate_dimension()
freeze_panes
¶
iter_cols
(
min_col=None
,
max_col=None
,
min_row=None
,
max_row=None
,
values_only=False
)
[source]
¶
Produces cells from the worksheet, by column. Specify the iteration range using indices of rows and columns.
If no indices are specified the range starts at A1.
If no cells are in the worksheet an empty tuple will be returned.
| 参数: |
|
|---|---|
| 返回类型: | generator |
iter_rows
(
min_row=None
,
max_row=None
,
min_col=None
,
max_col=None
,
values_only=False
)
[source]
¶
Produces cells from the worksheet, by row. Specify the iteration range using indices of rows and columns.
If no indices are specified the range starts at A1.
If no cells are in the worksheet an empty tuple will be returned.
| 参数: |
|
|---|---|
| 返回类型: | generator |
max_column
¶
The maximum column index containing data (1-based)
| 类型: | int |
|---|
max_row
¶
The maximum row index containing data (1-based)
| 类型: | int |
|---|
merge_cells
(
range_string=None
,
start_row=None
,
start_column=None
,
end_row=None
,
end_column=None
)
[source]
¶
Set merge on a cell range. Range is a cell range (e.g. A1:E1)
merged_cell_ranges
¶
Return a copy of cell ranges
注意
Deprecated: Use ws.merged_cells.ranges
mime_type
= 'application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml'
¶
min_column
¶
The minimum column index containing data (1-based)
| 类型: | int |
|---|
min_row
¶
The minimium row index containing data (1-based)
| 类型: | int |
|---|
move_range
(
cell_range
,
rows=0
,
cols=0
,
translate=False
)
[source]
¶
Move a cell range by the number of rows and/or columns: down if rows > 0 and up if rows < 0 right if cols > 0 and left if cols < 0 Existing cells will be overwritten. Formulae and references will not be updated.
page_breaks
¶
print_area
¶
The print area for the worksheet, or None if not set. To set, supply a range like ‘A1:D4’ or a list of ranges.
print_title_cols
¶
Columns to be printed at the left side of every page (ex: ‘A:C’)
print_title_rows
¶
Rows to be printed at the top of every page (ex: ‘1:3’)
print_titles
¶
rows
¶
Produces all cells in the worksheet, by row (see
iter_rows()
)
| 类型: | generator |
|---|
selected_cell
¶
sheet_view
¶
show_gridlines
¶
show_summary_below
¶
show_summary_right
¶
tables
¶
unmerge_cells
(
range_string=None
,
start_row=None
,
start_column=None
,
end_row=None
,
end_column=None
)
[source]
¶
Remove merge on a cell range. Range is a cell range (e.g. A1:E1)
值
¶
Produces all cell values in the worksheet, by row
| 类型: | generator |
|---|
openpyxl.worksheet.worksheet.
isgenerator
(
obj
)
¶