File: hide_sheet.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 (33 lines) | stat: -rw-r--r-- 1,023 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
#######################################################################
#
# Example of how to hide a worksheet with XlsxWriter.
#
# SPDX-License-Identifier: BSD-2-Clause
# Copyright 2013-2023, John McNamara, jmcnamara@cpan.org
#
import xlsxwriter

workbook = xlsxwriter.Workbook("hide_sheet.xlsx")
worksheet1 = workbook.add_worksheet()
worksheet2 = workbook.add_worksheet()
worksheet3 = workbook.add_worksheet()

worksheet1.set_column("A:A", 30)
worksheet2.set_column("A:A", 30)
worksheet3.set_column("A:A", 30)

# Hide Sheet2. It won't be visible until it is unhidden in Excel.
worksheet2.hide()

worksheet1.write("A1", "Sheet2 is hidden")
worksheet2.write("A1", "Now it's my turn to find you!")
worksheet3.write("A1", "Sheet2 is hidden")

# Note, you can't hide the "active" worksheet, which generally is the
# first worksheet, since this would cause an Excel error. So, in order to hide
# the first sheet you will need to activate another worksheet:
#
#    worksheet2.activate()
#    worksheet1.hide()

workbook.close()