Agrupar y desagrupar filas y columnas en Python

Gestión de grupos y desagrupaciones de filas y columnas en Aspose.Cells for Python via Java

Cómo agrupar filas y columnas en Python

Es posible agrupar filas o columnas llamando a los métodos groupRows y groupColumns de la colección Cells. Ambos métodos toman los siguientes parámetros:

  • Índice de primera fila/columna, la primera fila o columna del grupo.
  • Índice de última fila/columna, la última fila o columna del grupo.
  • Está oculto, un parámetro booleano que especifica si se deben ocultar filas/columnas después de agrupar o no.

Python Código

 def group_rows_columns(self):

\# Instantiating a Workbook object by excel file path

workbook = self.Workbook(self.dataDir + 'Book1.xls')

\# Accessing the first worksheet in the Excel file

worksheet = workbook.getWorksheets().get(0)

cells = worksheet.getCells()

\# Grouping first six rows (from 0 to 5) and making them hidden by passing true

cells.groupRows(0,5,True)

\# Grouping first three columns (from 0 to 2) and making them hidden by passing true

cells.groupColumns(0,2,True)

\# Saving the modified Excel file in default (that is Excel 2003) format

workbook.save(self.dataDir + "Group Rows And Columns.xls")

print "Group Rows And Columns Successfully." 

Cómo desagrupar filas y columnas usando Python

Desagrupe filas o columnas agrupadas llamando a los métodos UngroupRows y UngroupColumns de la colección Cells. Ambos métodos toman los mismos parámetros:

  • Índice de la primera fila o columna, la primera fila/columna que se desagrupará.
  • Índice de la última fila o columna, la última fila/columna que se desagrupará.

Python Código

 def ungroup_rows_columns(self):

\# Instantiating a Workbook object by excel file path

workbook = self.Workbook(self.dataDir + 'Group Rows And Columns.xls')

\# Accessing the first worksheet in the Excel file

worksheet = workbook.getWorksheets().get(0)

cells = worksheet.getCells()

\# Ungrouping first six rows (from 0 to 5)

cells.ungroupRows(0,5)

\# Ungrouping first three columns (from 0 to 2)

cells.ungroupColumns(0,2)

\# Saving the modified Excel file in default (that is Excel 2003) format

workbook.save(self.dataDir + "Ungroup Rows And Columns.xls")

print "Ungroup Rows And Columns Successfully." 

Descargar código de ejecución

Descargar**Agrupar y desagrupar filas y columnas (Aspose.Cells)**de cualquiera de los sitios de codificación social mencionados a continuación: