Implementa la Cell.FormulaLocal simile a Excel VBA Range.FormulaLocal

Possibili Scenari di Utilizzo

Le formule di Microsoft Excel possono avere nomi diversi in diverse località, regioni o lingue. Ad esempio, la funzione SUM viene chiamata SUMME in tedesco. Aspose.Cells non può lavorare con nomi di funzioni non in inglese. In Microsoft Excel VBA, c’è la proprietà Range.FormulaLocal che restituisce il nome della funzione in base alla lingua o alla regione. Aspose.Cells fornisce anche la proprietà Cell.FormulaLocal a questo scopo. Tuttavia, questa proprietà funzionerà solo quando implementerai il metodo GlobalizationSettings.GetLocalFunctionName(string standardName).

Implementa Cell.FormulaLocal simile a Excel VBA Range.FormulaLocal

Il seguente codice di esempio spiega come implementare il metodo GlobalizationSettings.GetLocalFunctionName(string standardName). Il metodo restituisce il nome locale della funzione standard. Se il nome della funzione standard è SUM, restituisce UserFormulaLocal_SUM. Puoi modificare il codice in base alle tue esigenze e restituire i nomi corretti delle funzioni locali come ad esempio SUM è SUMME in tedesco e TEXT è ТЕКСТ in russo. Consulta anche l’output della console del codice di esempio qui sotto a titolo di riferimento.

Codice di Esempio

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

Output della console

Formula Local: =UserFormulaLocal_SUM(A1:A2)

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