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

Possibili Scenari di Utilizzo

Le formule di Microsoft Excel potrebbero avere nomi diversi a seconda delle localizzazioni, regioni o lingue. Per esempio, la funzione SUM si chiama SUMME in Tedesco. Aspose.Cells non può funzionare con nomi di funzioni non in inglese. In Microsoft Excel VBA, esiste una proprietà Range.FormulaLocal che restituisce il nome della funzione secondo la sua lingua o regione. Aspose.Cells fornisce anche la proprietà Cell.FormulaLocal a questo scopo. Tuttavia, questa proprietà funzionerà solo quando si implementa il metodo GlobalizationSettings.getLocalFunctionName(String standardName)

Implementa Cell.FormulaLocal simile a Excel VBA Range.FormulaLocal

Il seguente esempio di codice 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 secondo le tue esigenze e restituire i nomi corretti delle funzioni locali, ad esempio SUM è SUMME in Tedesco e TEXT è ТЕКСТ in Russo. Guarda anche l’output sulla console del codice di esempio di seguito per un riferimento.

Codice di Esempio

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

Output della console

 Formula Local: =UserFormulaLocal_SUM(A1:A2)

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