Aspose.Cells, Excel, ICustomFunction, bir dizi değeri döndürür
ICustomFunction, Aspose.Cells for Java sürümü ile kullanımdan kaldırılmıştır 20.8. Lütfen AbstractCalculationEngine sınıfını kullanın. AbstractCalculationEngine sınıfının kullanımı aşağıdaki makalede açıklanmaktadır.
Aspose.Cells, Microsoft Excel tarafından desteklenmeyen kullanıcı tanımlı veya özel işlevleri uygulamak için kullanılan ICustomFunction arayüzünü sağlar.
Çoğunlukla ICustomFunction arayüz methodunu uyguladığınızda tek hücre değeri döndürmeniz gerekir. Ancak bazen, ICustomFunction aralığındaki değerleri döndürmeniz gerekir. Bu makale, ICustomFunction aralığındaki değerlerin nasıl döndürüleceğini açıklayacaktır.
ICustomFunction Kullanarak Bir Değer Aralığı Döndürme
Aşağıdaki kod ICustomFunction uygular ve yöntemi aracılığıyla değer aralığını döndürür. Referans için, kod ile oluşturulan çıktı Excel dosyasını ve pdf dosyasını kontrol edin.
Bir sınıf oluşturun ve içine CalculateCustomFunction fonksiyonunu ekleyin. Bu sınıf ICustomFunction‘ı uygular.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
import java.util.ArrayList; | |
import com.aspose.cells.AbstractCalculationEngine; | |
import com.aspose.cells.CalculationData; | |
import com.aspose.cells.DateTime; | |
public class CustomFunctionStaticValue extends AbstractCalculationEngine { | |
@Override | |
public void calculate(CalculationData calculationData) { | |
calculationData.setCalculatedValue(new Object[][] { new Object[] { new DateTime(2015, 6, 12, 10, 6, 30), 2 }, | |
new Object[] { 3.0, "Test" } }); | |
} | |
} |
Şimdi yukarıdaki işlevi programınıza ekleyin.
// 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(ReturningRangeOfValues.class); | |
Workbook wb = new Workbook(); | |
Cells cells = wb.getWorksheets().get(0).getCells(); | |
Cell cell = cells.get(0, 0); | |
cell.setArrayFormula("=MYFUNC()", 2, 2); | |
Style style = cell.getStyle(); | |
style.setNumber(14); | |
cell.setStyle(style); | |
CalculationOptions copt = new CalculationOptions(); | |
copt.setCustomFunction(new CustomFunctionStaticValue()); | |
wb.calculateFormula(copt); | |
// Save to xlsx by setting the calc mode to manual | |
wb.getSettings().getFormulaSettings().setCalculationMode(CalcModeType.MANUAL); | |
wb.save(dataDir + "output.xlsx"); | |
// Save to pdf | |
wb.save(dataDir + "output.pdf"); | |