تنفيذ 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-Java
package AsposeCellsExamples.WorkbookSettings;
import com.aspose.cells.*;
import AsposeCellsExamples.Utils;
public class Implement_Cell_FormulaLocal_SimilarTo_Range_FormulaLocal {
//Implement GlobalizationSettings class
class GS extends GlobalizationSettings {
public String getLocalFunctionName(String standardName)
{
//Change the SUM function name as per your needs.
if(standardName.equals("SUM"))
{
return "UserFormulaLocal_SUM";
}
//Change the AVERAGE function name as per your needs.
if (standardName.equals("AVERAGE"))
{
return "UserFormulaLocal_AVERAGE";
}
return "";
}//getLocalFunctionName
}//GS extends GlobalizationSettings
public void Run() throws Exception {
//Create workbook
Workbook wb = new Workbook();
//Assign GlobalizationSettings implementation class
wb.getSettings().setGlobalizationSettings(new GS());
//Access first worksheet
Worksheet ws = wb.getWorksheets().get(0);
//Access some cell
Cell cell = ws.getCells().get("C4");
//Assign SUM formula and print its FormulaLocal
cell.setFormula("SUM(A1:A2)");
System.out.println("Formula Local: " + cell.getFormulaLocal());
//Assign AVERAGE formula and print its FormulaLocal
cell.setFormula("=AVERAGE(B1:B2, B5)");
System.out.println("Formula Local: " + cell.getFormulaLocal());
}
public static void main(String[] args) throws Exception {
System.out.println("Aspose.Cells for Java Version: " + CellsHelper.getVersion());
Implement_Cell_FormulaLocal_SimilarTo_Range_FormulaLocal pg = new Implement_Cell_FormulaLocal_SimilarTo_Range_FormulaLocal();
pg.Run();
// Print the message
System.out.println("Implement_Cell_FormulaLocal_SimilarTo_Range_FormulaLocal executed successfully.");
}
}

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

 Formula Local: =UserFormulaLocal_SUM(A1:A2)

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