-
-
Notifications
You must be signed in to change notification settings - Fork 640
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature request: Checkbox #1092
Comments
yes, this one |
@areqq and @tjpartridge I've pushed initial support for this feature to main. You can now use it as follows: 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() Output: There is still some work to be done to ensure that this feature is compatible with Tables and Table formats. Also, it currently modifies a user supplied format (such as |
I fixed this and added some tests. You can now do something like this using Polars (or with just XlsxWriter): import polars as pl
# Create a Pandas dataframe with some sample data.
df = pl.DataFrame(
{
"Region": ["North", "South", "East", "West"],
"Target": [100, 70, 90, 120],
"On-track": [False, True, True, False],
}
)
# Write the dataframe to a new Excel file with formatting options.
df.write_excel(
workbook="polars_checkbox.xlsx",
# Set the checkbox format for the "On-track" boolean column.
column_formats={"On-track": {"checkbox": True}},
# Set an alternative table style.
table_style="Table Style Light 9",
# Autofit the column widths.
autofit=True,
) Output:
This is probably going to need a reasonable refactoring of the Format code so I am going to tackle that in the next release. As such I am going to push the current code out in a new release in the next 12 hours. |
This feature is available in XlsxWriter v3.2.2. |
Question
Is it possible to insert checkbox into cell?
The text was updated successfully, but these errors were encountered: