تنفيذ Cell.FormulaLocal مماثل لـ Excel VBA Range.FormulaLocal

سيناريوهات الاستخدام المحتملة

قد تكون للمعادلات في Microsoft Excel أسماء مختلفة في لغات أو مناطق أو لهجات مختلفة. على سبيل المثال، تسمى وظيفة SUM باسم SUMME في اللغة الألمانية. لا يمكن لـ Aspose.Cells العمل مع أسماء الوظائف غير الإنجليزية. في Microsoft Excel VBA، هناك خاصية Range.FormulaLocal التي تعيد اسم الوظيفة وفقًا للغتها أو منطقتها. كما يوفر Aspose.Cells أيضًا الخاصية Cell.FormulaLocal لهذا الغرض. ومع ذلك، ستعمل هذه الخاصية فقط عند تنفيذ الأسلوب GlobalizationSettings.GetLocalFunctionName(string standardName).

تنفيذ Cell.FormulaLocal مماثل لـ Excel VBA Range.FormulaLocal

يوضح الكود البرنامج النموذجي التالي كيفية تنفيذ GlobalizationSettings.GetLocalFunctionName(string standardName). يُعيد الأسلوب اسم الوظيفة المحلية القياسية. إذا كان اسم الوظيفة القياسية هو SUM، فإنه يُعيد UserFormulaLocal_SUM. يمكنك تغيير الكود وفقًا لاحتياجاتك وإعادة أسماء الوظائف المحلية الصحيحة على سبيل المثال، SUM هي SUMME في اللغة الألمانية وTEXT هي ТЕКСТ في اللغة الروسية. يُرجى أيضًا الاطلاع على مخرجات وحدة التحكم في الكود البرنامجي المعطى أدناه للإشارة.

الكود المثالي

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Aspose.Cells.Examples.CSharp.WorkbookSettings
{
class Implement_Cell_FormulaLocal_SimilarTo_Range_FormulaLocal
{
//Implement GlobalizationSettings class
class GS : GlobalizationSettings
{
public override string GetLocalFunctionName(string standardName)
{
//Change the SUM function name as per your needs.
if (standardName == "SUM")
{
return "UserFormulaLocal_SUM";
}
//Change the AVERAGE function name as per your needs.
if (standardName == "AVERAGE")
{
return "UserFormulaLocal_AVERAGE";
}
return "";
}//GetLocalFunctionName
}//GS:GlobalizationSettings
public static void Run()
{
//Create workbook
Workbook wb = new Workbook();
//Assign GlobalizationSettings implementation class
wb.Settings.GlobalizationSettings = new GS();
//Access first worksheet
Worksheet ws = wb.Worksheets[0];
//Access some cell
Cell cell = ws.Cells["C4"];
//Assign SUM formula and print its FormulaLocal
cell.Formula = "SUM(A1:A2)";
Console.WriteLine("Formula Local: " + cell.FormulaLocal);
//Assign AVERAGE formula and print its FormulaLocal
cell.Formula = "=AVERAGE(B1:B2, B5)";
Console.WriteLine("Formula Local: " + cell.FormulaLocal);
}
}
}

مخرجات الوحدة

Formula Local: =UserFormulaLocal_SUM(A1:A2)

Formula Local: =UserFormulaLocal_AVERAGE(B1:B2,B5)