File: chart_styles.py

package info (click to toggle)
xlsxwriter 3.1.9-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 56,308 kB
  • sloc: python: 51,511; javascript: 7,768; sh: 284; makefile: 195; perl: 75
file content (41 lines) | stat: -rw-r--r-- 1,409 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#######################################################################
#
# An example showing all 48 default chart styles available in Excel 2007
# using Python and XlsxWriter. Note, these styles are not the same as
# the styles available in Excel 2013.
#
# SPDX-License-Identifier: BSD-2-Clause
# Copyright 2013-2023, John McNamara, jmcnamara@cpan.org
#
import xlsxwriter

workbook = xlsxwriter.Workbook("chart_styles.xlsx")

# Show the styles for all of these chart types.
chart_types = ["column", "area", "line", "pie"]

for chart_type in chart_types:
    # Add a worksheet for each chart type.
    worksheet = workbook.add_worksheet(chart_type.title())
    worksheet.set_zoom(30)
    style_number = 1

    # Create 48 charts, each with a different style.
    for row_num in range(0, 90, 15):
        for col_num in range(0, 64, 8):
            chart = workbook.add_chart({"type": chart_type})
            chart.add_series({"values": "=Data!$A$1:$A$6"})
            chart.set_title({"name": "Style %d" % style_number})
            chart.set_legend({"none": True})
            chart.set_style(style_number)

            worksheet.insert_chart(row_num, col_num, chart)
            style_number += 1

# Create a worksheet with data for the charts.
data_worksheet = workbook.add_worksheet("Data")
data = [10, 40, 50, 20, 10, 50]
data_worksheet.write_column("A1", data)
data_worksheet.hide()

workbook.close()