Enable CSS Custom Properties while saving to HTML with Python.NET

Possible Usage Scenarios

When you save your Excel file to HTML, for scenarios where there are multiple occurrences of one base64 image, using CSS custom properties allows the image data to be saved only once. This improves the performance of the resultant HTML. Use the HtmlSaveOptions.enable_css_custom_properties attribute and set it to True while saving to HTML.

todo:image_alt_text

Enable CSS Custom Properties while saving to HTML

The following sample code demonstrates using the HtmlSaveOptions.enable_css_custom_properties attribute. The screenshot shows the effect when this property is not set to True. Download the sample Excel file used in this code and the output HTML generated for reference.

Sample Code

import os
from aspose.cells import Workbook, HtmlSaveOptions

# For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
source_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "source")
output_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "output")

# Load sample workbook
wb = Workbook(os.path.join(source_dir, "sampleEnableCssCustomProperties.xlsx"))

# Configure HTML save options
opts = HtmlSaveOptions()
opts.export_images_as_base64 = True
opts.enable_css_custom_properties = True

# Save the workbook in HTML
wb.save(os.path.join(output_dir, "outputEnableCssCustomProperties.html"), opts)