Implémenter Cell.FormulaLocal similaire à Excel VBA Range.FormulaLocal

Scénarios d’utilisation possibles

Les formules Microsoft Excel peuvent avoir des noms différents dans différentes langues ou régions. Par exemple, la fonction SUM est appelée SUMME en allemand. Aspose.Cells ne peut pas fonctionner avec des noms de fonction non anglais. En VBA Excel, il existe la propriété Range.FormulaLocal qui renvoie le nom de la fonction selon sa langue ou sa région. Aspose.Cells fournit également la propriété Cell.FormulaLocal à cette fin. Cependant, cette propriété ne fonctionnera que si vous implémentez GlobalizationSettings.GetLocalFunctionName(string standardName) méthode.

Implémenter Cell.FormulaLocal similaire à Excel VBA Range.FormulaLocal

Le code d’exemple suivant explique comment implémenter la méthode GlobalizationSettings.GetLocalFunctionName(string standardName). La méthode renvoie le nom local de la fonction standard. Si le nom de la fonction standard est SUM, elle renvoie UserFormulaLocal_SUM. Vous pouvez modifier le code selon vos besoins et renvoyer les noms de fonction locaux corrects, par exemple SUM est SUMME en allemand et TEXT est ТЕКСТ en russe. Veuillez également consulter la sortie console du code d’exemple ci-dessous pour référence.

Code d’exemple

// 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);
}
}
}

Sortie console

Formula Local: =UserFormulaLocal_SUM(A1:A2)

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