Bir Aralıktaki Verileri Arayın ve Değiştirin
Contents
[
Hide
]
Bazen, istenen aralığın dışındaki tüm hücre değerlerini yok sayarak bir aralıktaki belirli verileri aramanız ve değiştirmeniz gerekir. Aspose.Cells, bir aramayı belirli bir aralıkla sınırlamanıza izin verir. Bu makale nasıl yapılacağını açıklıyor.
Aspose.Cells şunları sağlar:FindOptions.setRange() veri ararken bir aralık belirtmek için yöntem.
Dizeyi aramak istediğinizi varsayalım**“Ara”** ve onunla değiştir**“yer değiştirmek”** aralıkta**E3:H6**. Aşağıdaki ekran görüntüsünde, “arama” dizesi birkaç hücrede görülebilir, ancak biz onu yalnızca belirli bir aralıkta değiştirmek istiyoruz, burada sarı renkle vurgulanmıştır.
Giriş dosyası
Kodun çalıştırılmasından sonra çıktı dosyası aşağıdaki gibi görünür. Aralık içindeki tüm “arama” dizeleri “değiştir” ile değiştirilmiştir.
Çıktı dosyası
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(SearchReplaceDataInRange.class); | |
Workbook workbook = new Workbook(dataDir + "input.xlsx"); | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
// Specify the range where you want to search | |
// Here the range is E3:H6 | |
CellArea area = CellArea.createCellArea("E3", "H6"); | |
// Specify Find options | |
FindOptions opts = new FindOptions(); | |
opts.setLookInType(LookInType.VALUES); | |
opts.setLookAtType(LookAtType.ENTIRE_CONTENT); | |
opts.setRange(area); | |
Cell cell = null; | |
do { | |
// Search the cell with value search within range | |
cell = worksheet.getCells().find("search", cell, opts); | |
// If no such cell found, then break the loop | |
if (cell == null) | |
break; | |
// Replace the cell with value replace | |
cell.putValue("replace"); | |
} while (true); | |
// Save the workbook | |
workbook.save(dataDir + "output.xlsx"); |