隐藏和显示行和列

介绍

有时,用户可能还需要隐藏工作表的某些行或列,然后再显示。 Microsoft Excel 提供此功能,因此为 Aspose.Cells。

控制行和列的可见性

Aspose.Cells提供了一个类,工作簿,代表一个 Microsoft Excel 文件。这工作簿类包含一个工作表集合允许访问 Excel 文件中的每个工作表。工作表由工作表班级。这工作表类提供了Cells代表工作表中所有单元格的集合。这Cellscollection 提供了多种方法来管理工作表中的行或列。下面讨论其中一些。

隐藏行或列

开发人员可以通过调用[隐藏行](https://reference.aspose.com/cells/java/com.aspose.cells/cells#hideRow(int)) 和[隐藏列](https://reference.aspose.com/cells/java/com.aspose.cells/cells#hideColumn(int) 的方法Cells分别收藏。这两种方法都将行/列索引作为参数来隐藏特定的行或列。

// 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.getSharedDataDir(HidingRowsandColumns.class) + "rows_cloumns/";
// Instantiating a Workbook object
Workbook workbook = new Workbook(dataDir + "book1.xls");
// Accessing the first worksheet in the Excel file
Worksheet worksheet = workbook.getWorksheets().get(0);
Cells cells = worksheet.getCells();
// Hiding the 3rd row of the worksheet
cells.hideRow(2);
// Hiding the 2nd column of the worksheet
cells.hideColumn(1);
// Saving the modified Excel file in default (that is Excel 2003) format
workbook.save(dataDir + "HidingRowsandColumns_out.xls");
// Print message
System.out.println("Rows and Columns hidden successfully.");

显示行和列

开发人员可以通过调用[取消隐藏行](https://reference.aspose.com/cells/java/com.aspose.cells/cells#unhideRow(int,%20double)) 和[取消隐藏列](https://reference.aspose.com/cells/java/com.aspose.cells/cells#unhideColumn(int,%20double) 的方法Cells分别收藏。两种方法都有两个参数:

  • 行或列索引 用于显示特定行或列的行或列的索引。
  • 行高或列宽 显示后分配给行或列的行高或列宽。
// 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.getSharedDataDir(UnhidingRowsandColumns.class) + "rows_cloumns/";
// Instantiating a Workbook object
Workbook workbook = new Workbook(dataDir + "book1.xls");
// Accessing the first worksheet in the Excel file
Worksheet worksheet = workbook.getWorksheets().get(0);
Cells cells = worksheet.getCells();
// Unhiding the 3rd row and setting its height to 13.5
cells.unhideRow(2, 13.5);
// Unhiding the 2nd column and setting its width to 8.5
cells.unhideColumn(1, 8.5);
// Saving the modified Excel file in default (that is Excel 2003) format
workbook.save(dataDir + "UnhidingRowsandColumns_out.xls");
// Print message
System.out.println("Rows and Columns unhidden successfully.");