Aspose.Cells kitaplığını kullanarak Microsoft Excel de bir dizi değeri döndüren soyut bir hesaplama motoru tanıtır. Varolan bir Excel dosyasını yükleyerek veya yeni bir Excel dosyası oluşturarak, Aspose.Cells tarafından sağlanan yöntemleri kullanarak bir dizi değeri alabiliriz ve sonucu döndürebiliriz. Son olarak, değiştirilmiş Excel dosyasını diske kaydederiz.
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 metodu aracılığıyla değerlerin aralığını döndürür.
Bir CalculateCustomFunction işlevi olan bir sınıf oluşturun. Bu sınıf, AbstractCalculationEngine uygular.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
public class CustomFunctionStaticValue : AbstractCalculationEngine | |
{ | |
public override void Calculate(CalculationData data) | |
{ | |
data.CalculatedValue = 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-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create workbook | |
Workbook workbook = new Workbook(); | |
Cells cells = workbook.Worksheets[0].Cells; | |
// Set formula | |
Cell cell = cells[0, 0]; | |
cell.SetArrayFormula("=MYFUNC()", 2, 2); | |
Style style = cell.GetStyle(); | |
style.Number = 14; | |
cell.SetStyle(style); | |
// Set calculation options for formula | |
CalculationOptions calculationOptions = new CalculationOptions(); | |
calculationOptions.CustomEngine = new CustomFunctionStaticValue(); | |
workbook.CalculateFormula(calculationOptions); | |
// Save to xlsx by setting the calc mode to manual | |
workbook.Settings.FormulaSettings.CalculationMode = CalcModeType.Manual; | |
workbook.Save(dataDir + "output_out.xlsx"); | |
// Save to pdf | |
workbook.Save(dataDir + "output_out.pdf"); |