Activando Hojas y Activando una Celda en la Hoja de Trabajo

Activando Hojas y Activando una Celda

Aspose.Cells proporciona llamadas de API específicas para activar una hoja y una celda. Por ejemplo, la propiedad WorksheetCollection.ActiveSheetIndex es útil para establecer la hoja activa en un libro. De manera similar, la propiedad Worksheet.ActiveCell se puede utilizar para establecer y obtener una celda activa en la hoja de trabajo.

Para asegurarte de que las barras de desplazamiento horizontal o vertical estén en la posición del índice de fila y columna que deseas mostrar datos específicos, utiliza las propiedades Worksheet.FirstVisibleRow y Worksheet.FirstVisibleColumn.

El siguiente ejemplo muestra cómo activar una hoja de cálculo y hacer una celda activa en ella. La siguiente salida se genera al ejecutar el código. Las barras de desplazamiento se desplazan para hacer que la 2ª fila y la 2ª columna sean su primera fila y columna visibles.

Establecer la celda B2 como celda activa

todo:image_alt_text

Código Java para establecer una hoja de cálculo activa en Excel

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(ActivatingSheetsandActivatingCell.class);
// Instantiate a new Workbook
Workbook workbook = new Workbook();
// Get the first worksheet in the workbook
Worksheet worksheet = workbook.getWorksheets().get(0);
// Get the cells in the worksheet
Cells cells = worksheet.getCells();
// Input data into B2 cell
cells.get(1, 1).putValue("Hello World!");
// Set the first sheet as an active sheet
workbook.getWorksheets().setActiveSheetIndex(0);
// Set B2 cell as an active cell in the worksheet
worksheet.setActiveCell("B2");
// Set the B column as the first visible column in the worksheet
worksheet.setFirstVisibleColumn(1);
// Set the 2nd row as the first visible row in the worksheet
worksheet.setFirstVisibleRow(1);
// Save the excel file
workbook.save(dataDir + "activecell.xls");