Ajuste de altura de fila y ancho de columna

Trabajar con filas

Ajuste de altura de fila

Aspose.Cells proporciona una clase,ILibro de trabajo que representa un archivo de Excel Microsoft. ÉlILibro de trabajo la clase contiene unIWorksheetCollectionque permite el acceso a cada hoja de trabajo en el archivo de Excel. Una hoja de trabajo está representada por elIHoja de trabajo clase. ÉlIHoja de trabajo la clase proporciona unICélulas colección que representa todas las celdas de la hoja de trabajo. ÉlICélulascolección proporciona varios métodos para administrar filas o columnas en una hoja de trabajo. Algunos de estos se discuten a continuación con más detalle.

Establecer la altura de una fila

Es posible establecer la altura de una sola fila llamando alICélulas colecciónEstablecerRowHeight método. ÉlEstablecerRowHeightEl método toma los siguientes parámetros de la siguiente manera:

  • Índice de fila, el índice de la fila cuya altura está cambiando.
  • Altura de la fila, el alto de fila que se aplicará en la fila.
//For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-C
//Path of input excel file
StringPtr sampleRowsAndColumns = dirPath->StringAppend(new String("sampleRowsAndColumns.xlsx"));
//Path of output excel file
StringPtr outputRowsAndColumns = outPath->StringAppend(new String("outputRowsAndColumns.xlsx"));
//Read input excel file
intrusive_ptr<IWorkbook> workbook = Factory::CreateIWorkbook(sampleRowsAndColumns);
//Accessing the first worksheet in the Excel file
intrusive_ptr<IWorksheet> worksheet = workbook->GetIWorksheets()->GetObjectByIndex(0);
//Setting the height of the second row to 35
worksheet->GetICells()->SetRowHeight(1, 35);
//Save the Excel file.
workbook->Save(outputRowsAndColumns);

Establecer la altura de todas las filas en una hoja de cálculo

Si los desarrolladores necesitan establecer la misma altura de fila para todas las filas de la hoja de cálculo, pueden hacerlo mediante elEstablecerAlturaEstándar metodo de laICélulasrecopilación.

//For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-C
//Path of input excel file
StringPtr sampleRowsAndColumns = dirPath->StringAppend(new String("sampleRowsAndColumns.xlsx"));
//Path of output excel file
StringPtr outputRowsAndColumns = outPath->StringAppend(new String("outputRowsAndColumns.xlsx"));
//Read input excel file
intrusive_ptr<IWorkbook> workbook = Factory::CreateIWorkbook(sampleRowsAndColumns);
//Accessing the first worksheet in the Excel file
intrusive_ptr<IWorksheet> worksheet = workbook->GetIWorksheets()->GetObjectByIndex(0);
// Setting the height of all rows in the worksheet to 25
worksheet->GetICells()->SetStandardHeight(25);
//Save the Excel file.
workbook->Save(outputRowsAndColumns);

Trabajar con columnas

Establecer el ancho de una columna

Establezca el ancho de una columna llamando alICélulas colecciónEstablecer ancho de columna método. ÉlEstablecer ancho de columnamétodo toma los siguientes parámetros:

  • índice de columna, el índice de la columna cuyo ancho está cambiando.
  • Ancho de columna, el ancho de columna deseado.
//For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-C
//Path of input excel file
StringPtr sampleRowsAndColumns = dirPath->StringAppend(new String("sampleRowsAndColumns.xlsx"));
//Path of output excel file
StringPtr outputRowsAndColumns = outPath->StringAppend(new String("outputRowsAndColumns.xlsx"));
//Read input excel file
intrusive_ptr<IWorkbook> workbook = Factory::CreateIWorkbook(sampleRowsAndColumns);
//Accessing the first worksheet in the Excel file
intrusive_ptr<IWorksheet> worksheet = workbook->GetIWorksheets()->GetObjectByIndex(0);
//Setting the width of the second column to 56.5
worksheet->GetICells()->SetColumnWidth(1, 56.5);
//Save the Excel file.
workbook->Save(outputRowsAndColumns);

Establecer el ancho de todas las columnas en una hoja de trabajo

Para establecer el mismo ancho de columna para todas las columnas de la hoja de trabajo, use elICélulas colecciónEstablecerAnchoEstándarmétodo.

//For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-C
//Path of input excel file
StringPtr sampleRowsAndColumns = dirPath->StringAppend(new String("sampleRowsAndColumns.xlsx"));
//Path of output excel file
StringPtr outputRowsAndColumns = outPath->StringAppend(new String("outputRowsAndColumns.xlsx"));
//Read input excel file
intrusive_ptr<IWorkbook> workbook = Factory::CreateIWorkbook(sampleRowsAndColumns);
//Accessing the first worksheet in the Excel file
intrusive_ptr<IWorksheet> worksheet = workbook->GetIWorksheets()->GetObjectByIndex(0);
//Setting the width of all columns in the worksheet to 20.5
worksheet->GetICells()->SetStandardWidth(20.5);
//Save the Excel file.
workbook->Save(outputRowsAndColumns);