from aspose.cells import BorderType, CellBorderType, StyleFlag, TextAlignmentType, Workbook from aspose.pydrawing import Color from os import os, path # For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET # The path to the documents directory. dataDir = RunExamples.GetDataDir(".") # Create directory if it is not already present. IsExists = path.isdir(dataDir) if notIsExists: os.makedirs(dataDir) # Instantiating a Workbook object workbook = Workbook() # Obtaining the reference of the first (default) worksheet by passing its sheet index worksheet = workbook.worksheets[0] # Adding a new Style to the styles style = workbook.create_style() # Setting the vertical alignment of the text in the "A1" cell style.vertical_alignment = TextAlignmentType.CENTER # Setting the horizontal alignment of the text in the "A1" cell style.horizontal_alignment = TextAlignmentType.CENTER # Setting the font color of the text in the "A1" cell style.font.color = Color.green # Shrinking the text to fit in the cell style.shrink_to_fit = True # Setting the bottom border color of the cell to red style.borders.get(BorderType.BOTTOM_BORDER).color = Color.red # Setting the bottom border type of the cell to medium style.borders.get(BorderType.BOTTOM_BORDER).line_style = CellBorderType.MEDIUM # Creating StyleFlag styleFlag = StyleFlag() styleFlag.horizontal_alignment = True styleFlag.vertical_alignment = True styleFlag.shrink_to_fit = True styleFlag.borders = True styleFlag.font_color = True # Accessing a column from the Columns collection column = worksheet.cells.columns[0] # Applying the style to the column column.apply_style(style, styleFlag) # Saving the Excel file workbook.save(dataDir + "book1.out.xls")