激活工作表和工作表中的单元格

激活工作表和激活单元

Aspose.Cells提供了特定的API调用来激活工作表和单元。例如,WorksheetCollection.ActiveSheetIndex属性对于在工作簿中设置活动工作表非常有用。同样,Worksheet.ActiveCell属性可用于设置和获取工作表中的活动单元。

要确保水平或垂直滚动条位于要显示特定数据的行和列索引位置,请使用Worksheet.FirstVisibleRowWorksheet.FirstVisibleColumn属性。

以下示例显示了如何激活工作表并使其中的活动单元。执行代码时会生成以下输出。滚动条会滚动,以使第二行和第二列成为它们的第一个可见行和列。

将B2单元设置为活动单元

todo:image_alt_text

设置Excel中的活动工作表的Java代码

// 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");