Ocultar y mostrar filas y columnas
Control de la visibilidad de filas y columnas
Aspose.Cells proporciona una clase,Libro de trabajo , que representa un archivo de Excel Microsoft. ÉlLibro de trabajo la clase contiene unColección de hojas de trabajo que permite a los desarrolladores acceder a cada hoja de trabajo en el archivo de Excel. Una hoja de trabajo está representada por elHoja de cálculo clase. ÉlHoja de cálculo la clase proporciona unCells colección que representa todas las celdas de la hoja de trabajo. ÉlCellscolección proporciona varios métodos para administrar filas o columnas en una hoja de trabajo. Algunos de estos se discuten a continuación.
Ocultar filas y columnas
Los desarrolladores pueden ocultar una fila o columna llamando alOcultarfila yOcultarColumna métodos de laCellscolección respectivamente. Ambos métodos toman el índice de fila y columna como parámetro para ocultar la fila o columna específica.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Creating a file stream containing the Excel file to be opened | |
FileStream fstream = new FileStream(dataDir + "book1.xls", FileMode.Open); | |
// Instantiating a Workbook object | |
// Opening the Excel file through the file stream | |
Workbook workbook = new Workbook(fstream); | |
// Accessing the first worksheet in the Excel file | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Hiding the 3rd row of the worksheet | |
worksheet.Cells.HideRow(2); | |
// Hiding the 2nd column of the worksheet | |
worksheet.Cells.HideColumn(1); | |
// Saving the modified Excel file | |
workbook.Save(dataDir + "output.out.xls"); | |
// Closing the file stream to free all resources | |
fstream.Close(); |
Mostrar filas y columnas
Los desarrolladores pueden mostrar cualquier fila o columna oculta llamando alMostrar Fila yMostrar columna métodos de laCellscolección respectivamente. Ambos métodos toman dos parámetros:
- Índice de fila o columna - el índice de una fila o columna que se utiliza para mostrar la fila o columna específica.
- Alto de fila o ancho de columna - la altura de fila o el ancho de columna asignado a la fila o columna después de mostrarse.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Creating a file stream containing the Excel file to be opened | |
FileStream fstream = new FileStream(dataDir + "book1.xls", FileMode.Open); | |
// Instantiating a Workbook object | |
// Opening the Excel file through the file stream | |
Workbook workbook = new Workbook(fstream); | |
// Accessing the first worksheet in the Excel file | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Unhiding the 3rd row and setting its height to 13.5 | |
worksheet.Cells.UnhideRow(2, 13.5); | |
// Unhiding the 2nd column and setting its width to 8.5 | |
worksheet.Cells.UnhideColumn(1, 8.5); | |
// Saving the modified Excel file | |
workbook.Save(dataDir + "output.xls"); | |
// Closing the file stream to free all resources | |
fstream.Close(); |
Ocultar varias filas y columnas
Los desarrolladores pueden ocultar varias filas o columnas a la vez llamando alOcultar Filas yOcultar columnas métodos de laCellscolección respectivamente. Ambos métodos toman el índice de fila o columna inicial y el número de filas o columnas que deben ocultarse como parámetros.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Creating a file stream containing the Excel file to be opened | |
FileStream fstream = new FileStream(dataDir + "book1.xls", FileMode.Open); | |
// Instantiating a Workbook object | |
// Opening the Excel file through the file stream | |
Workbook workbook = new Workbook(fstream); | |
// Accessing the first worksheet in the Excel file | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Hiding 3,4 and 5 rows in the worksheet | |
worksheet.Cells.HideRows(2, 3); | |
// Hiding 2 and 3 columns in the worksheet | |
worksheet.Cells.HideColumns(1, 2); | |
// Saving the modified Excel file | |
workbook.Save(dataDir + "outputxls"); | |
// Closing the file stream to free all resources | |
fstream.Close(); |