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

Scénarios d’utilisation possibles

Microsoft Les formules Excel peuvent avoir des noms différents selon les paramètres régionaux, les régions ou les langues. Par exemple,SOMMEla fonction s’appelleÉTÉ en allemand. Aspose.Cells ne peut pas fonctionner avec des noms de fonction non anglais. Dans Microsoft Excel VBA, il y aRange.FormulaLocalpropriété qui renvoie le nom de la fonction selon sa langue ou sa région. Aspose.Cells fournit égalementCell.FormulaLocalpropriété à cet effet. Cependant, cette propriété ne fonctionnera que lorsque vous implémenterezGlobalizationSettings.GetLocalFunctionName(string standardName)méthode.

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

L’exemple de code suivant explique comment implémenterGlobalizationSettings.GetLocalFunctionName(string standardName) méthode. La méthode renvoie le nom local de la fonction standard. Si le nom de la fonction standard estSOMME , ça revientUserFormulaLocal_SUM Vous pouvez modifier le code selon vos besoins et renvoyer les noms de fonction locaux corrects, par exempleSOMME estÉTÉ en allemand etTEXTE estТЕКСТen russe. Veuillez également consulter la sortie de la console de l’exemple de code ci-dessous pour référence.

Exemple de code

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