-
-
Notifications
You must be signed in to change notification settings - Fork 639
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature request #1092
- Loading branch information
Showing
28 changed files
with
809 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
.. SPDX-License-Identifier: BSD-2-Clause | ||
Copyright (c) 2013-2025, John McNamara, jmcnamara@cpan.org | ||
.. _ex_checkbox: | ||
|
||
Example: Inserting a checkbox in a Worksheet | ||
============================================ | ||
|
||
An example of adding checkbox boolean values to a worksheet. | ||
|
||
.. image:: _images/checkbox.png | ||
|
||
.. literalinclude:: ../../../examples/checkbox.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
############################################################################## | ||
# | ||
# An example of adding checkbox boolean values to a worksheet using the the | ||
# XlsxWriter Python module. | ||
# | ||
# SPDX-License-Identifier: BSD-2-Clause | ||
# | ||
# Copyright (c) 2013-2025, John McNamara, jmcnamara@cpan.org | ||
# | ||
import xlsxwriter | ||
|
||
# Create a new Excel file object. | ||
workbook = xlsxwriter.Workbook("checkbox.xlsx") | ||
|
||
# Add a worksheet to the workbook. | ||
worksheet = workbook.add_worksheet() | ||
|
||
# Create some formats to use in the worksheet. | ||
bold = workbook.add_format({"bold": True}) | ||
light_red = workbook.add_format({"bg_color": "#FFC7CE"}) | ||
light_green = workbook.add_format({"bg_color": "#C6EFCE"}) | ||
|
||
# Set the column width for clarity. | ||
worksheet.set_column(0, 0, 30) | ||
|
||
# Write some descriptions. | ||
worksheet.write(1, 0, "Some simple checkboxes:", bold) | ||
worksheet.write(4, 0, "Some checkboxes with cell formats:", bold) | ||
|
||
# Insert some boolean checkboxes to the worksheet. | ||
worksheet.insert_checkbox(1, 1, False) | ||
worksheet.insert_checkbox(2, 1, True) | ||
|
||
# Insert some checkboxes with cell formats. | ||
worksheet.insert_checkbox(4, 1, False, light_red) | ||
worksheet.insert_checkbox(5, 1, True, light_green) | ||
|
||
# Close the workbook. | ||
workbook.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
############################################################################### | ||
# | ||
# FeaturePropertyBag - A class for writing the Excel XLSX featurePropertyBag.xml | ||
# file. | ||
# | ||
# SPDX-License-Identifier: BSD-2-Clause | ||
# | ||
# Copyright (c) 2013-2025, John McNamara, jmcnamara@cpan.org | ||
# | ||
|
||
# Package imports. | ||
from . import xmlwriter | ||
|
||
|
||
class FeaturePropertyBag(xmlwriter.XMLwriter): | ||
""" | ||
A class for writing the Excel XLSX FeaturePropertyBag file. | ||
""" | ||
|
||
########################################################################### | ||
# | ||
# Private API. | ||
# | ||
########################################################################### | ||
|
||
def _assemble_xml_file(self): | ||
# Assemble and write the XML file. | ||
|
||
# Write the XML declaration. | ||
self._xml_declaration() | ||
|
||
# Write the FeaturePropertyBags element. | ||
self._write_feature_property_bags() | ||
|
||
# Write the Checkbox bag element. | ||
self._write_checkbox_bag() | ||
|
||
# Write the XFControls bag element. | ||
self._write_xf_control_bag() | ||
|
||
# Write the XFComplement bag element. | ||
self._write_xf_compliment_bag() | ||
|
||
# Write the XFComplements bag element. | ||
self._write_xf_compliments_bag() | ||
|
||
self._xml_end_tag("FeaturePropertyBags") | ||
|
||
# Close the file. | ||
self._xml_close() | ||
|
||
########################################################################### | ||
# | ||
# XML methods. | ||
# | ||
########################################################################### | ||
|
||
def _write_feature_property_bags(self): | ||
# Write the <FeaturePropertyBags> element. | ||
|
||
xmlns = ( | ||
"http://schemas.microsoft.com/office/spreadsheetml/2022/featurepropertybag" | ||
) | ||
|
||
attributes = [("xmlns", xmlns)] | ||
|
||
self._xml_start_tag("FeaturePropertyBags", attributes) | ||
|
||
def _write_checkbox_bag(self): | ||
# Write the Checkbox <bag> element. | ||
attributes = [("type", "Checkbox")] | ||
|
||
self._xml_empty_tag("bag", attributes) | ||
|
||
def _write_xf_control_bag(self): | ||
# Write the XFControls<bag> element. | ||
attributes = [("type", "XFControls")] | ||
|
||
self._xml_start_tag("bag", attributes) | ||
|
||
# Write the bagId element. | ||
self._write_bag_id("CellControl", 0) | ||
|
||
self._xml_end_tag("bag") | ||
|
||
def _write_xf_compliment_bag(self): | ||
# Write the XFComplement <bag> element. | ||
attributes = [("type", "XFComplement")] | ||
|
||
self._xml_start_tag("bag", attributes) | ||
|
||
# Write the bagId element. | ||
self._write_bag_id("XFControls", 1) | ||
|
||
self._xml_end_tag("bag") | ||
|
||
def _write_xf_compliments_bag(self): | ||
# Write the _write_xf_compliment_bag<bag> element. | ||
attributes = [ | ||
("type", "XFComplements"), | ||
("extRef", "XFComplementsMapperExtRef"), | ||
] | ||
|
||
self._xml_start_tag("bag", attributes) | ||
self._xml_start_tag("a", [("k", "MappedFeaturePropertyBags")]) | ||
|
||
self._write_bag_id("", 2) | ||
|
||
self._xml_end_tag("a") | ||
self._xml_end_tag("bag") | ||
|
||
def _write_bag_id(self, key, bag_id): | ||
# Write the <bagId> element. | ||
attributes = [] | ||
|
||
if key: | ||
attributes = [("k", key)] | ||
|
||
self._xml_data_element("bagId", bag_id, attributes) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.