Working with ContentTypeProperties
Aspose.Cells for Python via .NET provides Workbook.content_type_properties.add() method to add custom ContentTypeProperties to an excel file. You may also make the property optional by setting the ContentTypeProperty.is_nillable property to true. The following code snippet demonstrates adding optional custom ContentTypeProperties to an excel file. The following image shows both properties that were added by the sample code.
The output file generated by the sample code is attached for reference.
Sample Code
from aspose.cells import FileFormatType, Workbook | |
from datetime import datetime | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# source directory | |
outputDir = RunExamples.Get_OutputDirectory() | |
workbook = Workbook(FileFormatType.XLSX) | |
index = workbook.content_type_properties.add("MK31", "Simple Data") | |
workbook.content_type_properties[index].is_nillable = False | |
index = workbook.content_type_properties.add("MK32", datetime.now().strftime("%Y-%m-%d'T'hh:%M:%S"), "DateTime") | |
workbook.content_type_properties[index].is_nillable = True | |
workbook.save(outputDir + "WorkingWithContentTypeProperties_out.xlsx") |