激活工作表并在工作表中激活 Cell
Contents
[
Hide
]
有时,当用户在 Excel 中打开 Microsoft Excel 文件时,您需要激活并显示特定的工作表。同样,您可能想要激活特定单元格并设置滚动条以显示活动单元格。 Aspose.Cells 能够完成所有这些任务,如下所示。
- 一个活动表是您正在处理的工作表:选项卡上的活动工作表名称默认为粗体。
- 一个活性细胞是一个选定的单元格,当您开始键入时,数据将被输入到该单元格中。一次只有一个细胞处于活动状态。活动单元格以粗边框突出显示。
激活工作表和激活 Cell
Aspose.Cells 提供用于激活工作表和单元格的特定 API 调用。例如,工作表集合.ActiveSheetIndex属性对于在工作簿中设置活动工作表很有用。同样,工作表.ActiveCell属性可用于设置和获取工作表中的活动单元格。
要确保水平或垂直滚动条位于要显示特定数据的行和列索引位置,请使用工作表.FirstVisibleRow和工作表.FirstVisibleColumn特性。
以下示例显示如何激活工作表并在其中创建活动单元格。执行代码时会生成以下输出。滚动条滚动使第 2 行和第 2 列成为它们的第一个可见行和列。
将 B2 单元格设置为活动单元格
Java 在 Excel 中设置活动工作表的代码
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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"); |
在评估模式,即;如果没有设置有效的许可证,活动工作表将始终是包含评估水印的工作表。此行为只能通过在应用程序启动时设置许可证来覆盖。