File: panes.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 (116 lines) | stat: -rw-r--r-- 3,123 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#######################################################################
#
# Example of using Python and the XlsxWriter module to create
# worksheet panes.
#
# SPDX-License-Identifier: BSD-2-Clause
# Copyright 2013-2023, John McNamara, jmcnamara@cpan.org
#
import xlsxwriter

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

worksheet1 = workbook.add_worksheet("Panes 1")
worksheet2 = workbook.add_worksheet("Panes 2")
worksheet3 = workbook.add_worksheet("Panes 3")
worksheet4 = workbook.add_worksheet("Panes 4")

#######################################################################
#
# Set up some formatting and text to highlight the panes.
#
header_format = workbook.add_format(
    {
        "bold": True,
        "align": "center",
        "valign": "vcenter",
        "fg_color": "#D7E4BC",
        "border": 1,
    }
)

center_format = workbook.add_format({"align": "center"})


#######################################################################
#
# Example 1. Freeze pane on the top row.
#
worksheet1.freeze_panes(1, 0)

# Other sheet formatting.
worksheet1.set_column("A:I", 16)
worksheet1.set_row(0, 20)
worksheet1.set_selection("C3")


# Some text to demonstrate scrolling.
for col in range(0, 9):
    worksheet1.write(0, col, "Scroll down", header_format)

for row in range(1, 100):
    for col in range(0, 9):
        worksheet1.write(row, col, row + 1, center_format)


#######################################################################
#
# Example 2. Freeze pane on the left column.
#
worksheet2.freeze_panes(0, 1)

# Other sheet formatting.
worksheet2.set_column("A:A", 16)
worksheet2.set_selection("C3")

# Some text to demonstrate scrolling.
for row in range(0, 50):
    worksheet2.write(row, 0, "Scroll right", header_format)
    for col in range(1, 26):
        worksheet2.write(row, col, col, center_format)


#######################################################################
#
# Example 3. Freeze pane on the top row and left column.
#
worksheet3.freeze_panes(1, 1)

# Other sheet formatting.
worksheet3.set_column("A:Z", 16)
worksheet3.set_row(0, 20)
worksheet3.set_selection("C3")
worksheet3.write(0, 0, "", header_format)

# Some text to demonstrate scrolling.
for col in range(1, 26):
    worksheet3.write(0, col, "Scroll down", header_format)

for row in range(1, 50):
    worksheet3.write(row, 0, "Scroll right", header_format)
    for col in range(1, 26):
        worksheet3.write(row, col, col, center_format)


#######################################################################
#
# Example 4. Split pane on the top row and left column.
#
# The divisions must be specified in terms of row and column dimensions.
# The default row height is 15 and the default column width is 8.43
#
worksheet4.split_panes(15, 8.43)

# Other sheet formatting.
worksheet4.set_selection("C3")

# Some text to demonstrate scrolling.
for col in range(1, 26):
    worksheet4.write(0, col, "Scroll", center_format)

for row in range(1, 50):
    worksheet4.write(row, 0, "Scroll", center_format)
    for col in range(1, 26):
        worksheet4.write(row, col, col, center_format)

workbook.close()