openpyxl
with the pip3
tool.openpyxl
.openpyxl
module, we import the Workbook
class. A workbook is the container for all other parts of the document.sample.xlsx
file with the save
method.cell
method.append
method, we can append a group of values at the bottom of the current sheet.append
method.sample.xlsx
file.load_workbook
method.cell
method to get the value of A3 cell.format()
function is used for neat output of dataon the console.iter_rows
method return cells from the worksheet as rows.iter_cols
method return cells from the worksheet as columns.RANDBETWEEN()
function.statistics
module is imported to provide some statistical functions, such as median and variance.data_only
option, we get the values from the cells, not the formula.statistics
module.auto_filter
attribute, which allows to set filtering and sorting conditions.dimensions
property returns the top-left and bottom-rightcell of the area of non-empty cells.min_row
and max_row
properties, we get the minimum and maximum row containing data. min_column
and max_column
properties, we get the minimum and maximum column containing data. get_sheet_names
method returns the names ofavailable sheets in a workbook.get_sheet_by_name()
method.create_sheet
method.sheetnames
attribute as well.remove_sheet
method.tabColor
property to a new colour.merge_cells
method and unmergedwith the unmerge_cells
method. When we merge cells, all cells but the top-left one are removed from the worksheet.Alignment
class from the openpyxl.styles
module.merge_cells
method.freeze_panes
property.openpyxl
does not do calculations; it writes formulas into cells.SUM()
function and style theoutput in bold font.Image
class from the openpyxl.drawing.image
module.Image
class is created. The icesid.png
image is located in the current working directory.add_image
method.openpyxl
library supports creation of various charts, including bar charts, line charts, area charts, bubble charts, scatter charts, and pie charts.openpyxl
supports chart creation within a worksheet only. Charts in existing workbooks will be lost.openpyxl.chart
module has tools to work with charts.Reference
class, we refer to the rows in the sheet thatrepresent data. In our case, these are the numbers of olympic gold medals.legend
and majorGridlines
attributes, weturn off the legends and major grid lines.varyColors
to True
, each bar has a differentcolour.add_chart
method.