Aspose.cells python via Net, 如何为整行设置Style, 我的无效

cell_sheet: Worksheet = self.frame_book.worksheets.get(0)
# 清除工作区痕迹
self.frame_grid.remove_traces(cell_sheet)
render_row: Row = cell_sheet.cells.rows[
cell_sheet.cells.min_data_row
]
error_cell: Cell = render_row.get_cell_or_null(0)

        if error_cell:
            # 设置注释
            self.frame_grid.add_comment(
                cell_sheet, error_cell.name,
                notes=self.frame_error
            )
            target_style: Style = render_row.get_style()
            target_style.foreground_color = Color.from_argb(
                192, 62, 28)
            target_style.pattern = BackgroundType.SOLID
            render_row.set_style(target_style)

@zengweiyu,

请参阅以下有关如何格式化工作表中的整行的示例代码以供参考。我已测试将您想要的颜色应用于第一行,效果很好。

# Adding a new Style to the styles
style = workbook.create_style()
# style.foreground_color = Color.red
style.foreground_color = Color.from_argb(192, 62, 28)
#  Setting the background pattern to vertical stripe
style.pattern = BackgroundType.SOLID
#  Creating StyleFlag
styleFlag = StyleFlag()
styleFlag.cell_shading = True
#  Accessing a row from the Rows collection
row = worksheet.cells.rows[0]
#  Assigning the Style object to the Style property of the row
row.apply_style(style, styleFlag)

另请参阅文档以供参考。
https://docs.aspose.com/cells/python-net/cells-formatting/#how-to-format-a-row

有效的,十分感谢 :smile: :smile: :smile: :smile: :smile: :smile:

@zengweiyu,

很高兴知道建议的代码段很好地满足了您的需求。如果您需要进一步的帮助或有其他问题或疑问,请随时与我们联系。