Satır ve Sütunları Otomatik Uydur
Otomatik Uydurma
Aspose.Cells, Workbook adında bir Microsoft Excel dosyasını temsil eden bir sınıf sağlar. Workbook sınıfı, Excel dosyasındaki her bir çalışma sayfasına erişim sağlayan Worksheets kolleksiyonuna sahiptir.
Bir çalışma sayfası Worksheet sınıfı tarafından temsil edilir. Worksheet sınıfı, çalışma sayfasını yönetmek için geniş bir yelpazede özellikler ve yöntemler sağlar. Bu makale, Worksheet sınıfını kullanarak satırları veya sütunları otomatik olarak uyarlama konusuna bakmaktadır.
Satırı Otomatik Uydurma - Basit
Bir satırın otomatik olarak genişlik ve yükseklik ayarlama yaklaşımındaki en doğrudan yol, Worksheet sınıfının autoFitRow metodunu çağırmaktır. autoFitRow metodu, yeniden boyutlandırılacak satırın dizinini (satır 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(AutoFitRowsandColumns.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); | |
// Auto-fitting the 2nd row of the worksheet | |
worksheet.autoFitRow(1); | |
// Auto-fitting the 1st column of the worksheet | |
worksheet.autoFitColumn(0); | |
// Saving the modified Excel file in default (that is Excel 2003) format | |
workbook.save(dataDir + "AutoFitRowsandColumns_out.xls"); | |
// Print message | |
System.out.println("Row and Column auto fit successfully."); |
Hücrelerin Aralığında Satırı Otomatik Uydur
Bir satır, birçok sütundan oluşur. Aspose.Cells, geliştiricilerin, satır içindeki hücre aralığındaki içerik temel alınarak satırın yüksekliğini otomatik ayarlamalarını sağlar ve bu işlevselliği sağlamak için autoFitRow metodunun aşırı yüklenmiş versiyonunu çağırabilir. Bu metod aşağıdaki parametreleri alır:
- Satır dizini, otomatik olarak uyarlama yapılacak satırın dizini.
- İlk sütun dizini, satırın ilk sütununun dizini.
- Son sütun dizini, satırın son sütununun dizini.
autoFitRow metodu, satırdaki tüm sütunların içeriğini kontrol eder ve ardından satırı otomatik olarak ayarlar.
// 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(AutoFitRowsinaRangeofCells.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); | |
// Auto-fitting the row of the worksheet | |
worksheet.autoFitRow(1, 0, 5); | |
// Saving the modified Excel file in default (that is Excel 2003) format | |
workbook.save(dataDir + "AutoFitRowsinaRangeofCells_out.xls"); | |
// Print message | |
System.out.println("Row auto fit successfully."); |
Kolay Otomatik Uydurma
Bir sütunun genişliğini ve yüksekliğini otomatik ayarlamanın en kolay yolu, Worksheet sınıfının autoFitColumn metodunu çağırmaktır. autoFitColumn metodu, yeniden boyutlandırılacak sütunun 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(AutoFitRowsandColumns.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); | |
// Auto-fitting the 2nd row of the worksheet | |
worksheet.autoFitRow(1); | |
// Auto-fitting the 1st column of the worksheet | |
worksheet.autoFitColumn(0); | |
// Saving the modified Excel file in default (that is Excel 2003) format | |
workbook.save(dataDir + "AutoFitRowsandColumns_out.xls"); | |
// Print message | |
System.out.println("Row and Column auto fit successfully."); |
Hücre Aralığındaki Otomatik Uydurma Sütunu
Bir sütun, birçok satırdan oluşur. İçeriğe göre otomatik olarak ayarlamak için, autoFitColumn metodu, aşağıdaki parametreleri alan aşırı yüklenmiş versiyonunu çağırabilirsiniz:
- Sütun indeksi, otomatik olarak uygun hale getirilmesi gereken sütunun indeksini temsil eder
- İlk satır indeksi, sütunun ilk satırının indeksini temsil eder.
- Son satır indeksi, sütunun son satırının indeksini temsil eder.
autoFitColumn metodu, tüm satırların içeriğini kontrol eder ve ardından sütunu otomatik olarak ayarlar.
// 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(AutoFitColumnsinaRangeofCells.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); | |
// Auto-fitting the Column of the worksheet | |
worksheet.autoFitColumn(4, 4, 6); | |
// Saving the modified Excel file in default (that is Excel 2003) format | |
workbook.save(dataDir + "AutoFitColumnsinaRangeofCells_out.xls"); | |
// Print message | |
System.out.println("Columns auto fit successfully."); |
Birleştirilmiş Hücreler için Satırları Otomatik Uydurma
Aspose.Cells ile AutoFitterOptions API’sını kullanarak birleştirilmiş hücreler için satırları otomatik olarak genişletebilirsiniz. AutoFitterOptions sınıfı, birleştirilmiş hücreler için satırları otomatik olarak genişletmek için kullanılabilecek bir AutoFitMergedCellsType özelliğini sağlar. AutoFitMergedCellsType, aşağıdaki üyelere sahip olan bir AutoFitMergedCellsType numaralandırmayı kabul eder:
- YOK: Birleştirilmiş hücreleri yok sayar.
- FIRST_LINE: yalnızca ilk satırın yüksekliğini genişletir.
- LAST_LINE: Sadece son satırın yüksekliğini genişletir.
- EACH_LINE: Her satırın yüksekliğini sadece genişletir.
// 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(AutofitRowsforMergedCells.class) + "RowsAndColumns/"; | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(); | |
// Accessing the first worksheet in the Excel file | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
// Create a range A1:B1 | |
Range range = worksheet.getCells().createRange(0, 0, 1, 2); | |
// Merge the cells | |
range.merge(); | |
// Insert value to the merged cell A1 | |
worksheet.getCells().get(0, 0).setValue("A quick brown fox jumps over the lazy dog. A quick brown fox jumps over the lazy dog....end"); | |
// Create a style object | |
Style style = worksheet.getCells().get(0, 0).getStyle(); | |
// Set wrapping text on | |
style.setTextWrapped(true); | |
// Apply the style to the cell | |
worksheet.getCells().get(0, 0).setStyle(style); | |
// Create an object for AutoFitterOptions | |
AutoFitterOptions options = new AutoFitterOptions(); | |
// Set auto-fit for merged cells | |
options.setAutoFitMergedCellsType(AutoFitMergedCellsType.EACH_LINE); | |
// Autofit rows in the sheet(including the merged cells) | |
worksheet.autoFitRows(options); | |
// Save the Excel file | |
workbook.save(dataDir + "AutofitRowsforMergedCells_out.xlsx"); |
Ayrıca, autoFitRows ve autoFitColumns metodlarının aşırı yüklenmiş sürümlerini kullanabilirsiniz. Bu sürümler belirli satır/ sütun aralığını ve bir AutoFitterOptions örneğini kabul eder ve seçilen satır/sütunların uygun AutoFitterOptions ayarlarıyla otomatik ayarlanmasını sağlar.
Yukarıda bahsedilen metodların imzaları aşağıdaki gibidir:
- autoFitRows(int startRow, int endRow, AutoFitterOptions options)
- autoFitColumns(int firstColumn, int lastColumn, AutoFitterOptions options)
Bilinmesi Gerekenler