Satır ve Sütunları Gizleme ve Gösterme
Giriş
Bazı durumlarda, çalışma sayfasının belirli satır veya sütunlarını gizlemek ve daha sonra göstermek gerekebilir. Bu özelliği Microsoft Excel sağladığı gibi Aspose.Cells de sağlar.
Satır ve Sütunların Görünürlüğünü Kontrol Etme
Aspose.Cells, bir Microsoft Excel dosyasını temsil eden Workbook sınıfını sağlar. Workbook sınıfı, Excel dosyasındaki her çalışma sayfasına erişim sağlayan bir WorksheetCollection içerir. Bir çalışma sayfası, Worksheet sınıfı tarafından temsil edilir. Worksheet sınıfı, çalışma sayfasındaki tüm hücreleri temsil eden bir Cells koleksiyonu sağlar. Cells koleksiyonu, çalışma sayfasındaki satır veya sütunları yönetmek için çeşitli yöntemler sağlar. Bunlardan bazıları aşağıda tartışılmıştır.
Satır veya Sütunları Gizleme
Geliştiriciler, Cells koleksiyonunun HideRow ve HideColumn yöntemlerini çağırarak bir satır veya sütunu gizleyebilir. Her iki yöntem de belirli bir satır veya sütunu gizlemek için satır/sütun indeksini parametre olarak alır.
// 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."); |
Satır ve Sütunları Gösterme
Geliştiriciler, Cells koleksiyonunun UnhideRow ve UnhideColumn yöntemlerini çağırarak herhangi bir gizlenmiş satır veya sütunu gösterebilir. Her iki yöntem de iki parametre alır:
- Satır veya sütun dizini - belirli bir satır veya sütunun gösterilmesi için kullanılan dizin.
- Satır yüksekliği veya sütun genişliği - Gösterildikten sonra satır veya sütuna atanan satır yüksekliği veya sütun genişliği.
// 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."); |