Node.js aracılığıyla C++ kullanarak Değişken Aralığını Döndürmek için AbstractCalculationEngine kullanımı
Aspose.Cells, Microsoft Excel tarafından desteklenmeyen kullanıcı tanımlı veya özel işlevleri uygulamak için kullanılan AbstractCalculationEngine sınıfını sağlar.
Bu makale, AbstractCalculationEngine aralığındaki değerlerin nasıl döndürüleceğini açıklayacaktır.
Aşağıdaki kod, AbstractCalculationEngine sınıfının kullanımını gösterir ve yöntemi aracılığıyla değer aralığını döndürür.
Bir sınıf oluşturun ve bir calculateCustomFunction fonksiyonu ekleyin. Bu sınıf AbstractCalculationEngine uygulamaktadır.
const AsposeCells = require("aspose.cells.node");
class CustomFunctionStaticValue extends AsposeCells.AbstractCalculationEngine {
calculate(data) {
data.setCalculatedValue([
[new Date(2015, 5, 12, 10, 6, 30), 2],
[3.0, "Test"]
]);
}
}
Şimdi yukarıdaki fonksiyonu programınızda kullanın
const AsposeCells = require("aspose.cells.node");
class CustomFunctionStaticValue extends AsposeCells.AbstractCalculationEngine {
calculate(data) {
data.setCalculatedValue([
[new Date(2015, 5, 12, 10, 6, 30), 2],
[3.0, "Test"]
]);
}
}
try {
const path = require("path");
const AsposeCells = require("aspose.cells.node");
// The path to the documents directory.
const dataDir = path.join(__dirname, "data");
// Create workbook
const workbook = new AsposeCells.Workbook();
const cells = workbook.getWorksheets().get(0).getCells();
// Set formula
const cell = cells.get(0, 0);
cell.setArrayFormula("=MYFUNC()", 2, 2);
const style = cell.getStyle();
style.setNumber(14);
cell.setStyle(style);
// Set calculation options for formula
const calculationOptions = new AsposeCells.CalculationOptions();
calculationOptions.setCustomEngine(new CustomFunctionStaticValue());
workbook.calculateFormula(calculationOptions);
// Save to xlsx by setting the calc mode to manual
workbook.getSettings().getFormulaSettings().setCalculationMode(AsposeCells.CalcModeType.Manual);
workbook.save(dataDir + "output_out.xlsx");
// Save to pdf
workbook.save(dataDir + "output_out.pdf");
} catch (error) {
console.error(`Test failed: ${error.message}`);
throw error;
}