Implementare Cell.FormulaLocal simile a Excel VBA Range.FormulaLocal
Possibili scenari di utilizzo
Microsoft Le formule di Excel possono avere nomi diversi in impostazioni locali, regioni o lingue diverse. Per esempio,SOMMAviene chiamata la funzioneESTATEinTedescoAspose.Cells non può funzionare con nomi di funzioni non inglesi. InMicrosoft Eccellere VBA, c’è* *un*Intervallo.FormulaLocale*proprietà che restituisce il nome della funzione in base alla lingua o all’area geografica. Aspose.Cells fornisce ancheCell.FormulaLocalproprietà a tale scopo. Tuttavia, questa proprietà funzionerà solo quando implementeraiGlobalizationSettings.getLocalFunctionName(String standardName) metodo.
Implementare Cell.FormulaLocal simile a Excel VBA Range.FormulaLocal
Il codice di esempio seguente spiega come implementareGlobalizationSettings.getLocalFunctionName(String standardName) metodo. Il metodo restituisce il nome locale della funzione standard. Se il nome della funzione standard èSOMMA, ritornaUserFormulaLocal_SUM. È possibile modificare il codice in base alle proprie esigenze e restituire i nomi delle funzioni locali corretti, ad esSOMMAèESTATEinTedescoeTESTOèТЕКСТinrusso. Si prega di consultare anche l’output della console del codice di esempio fornito di seguito per un riferimento.
Codice d’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."); | |
} | |
} |
Uscita console
Formula Local: =UserFormulaLocal_SUM(A1:A2)
Formula Local: =UserFormulaLocal_AVERAGE(B1:B2,B5)