Excel VBA Range.FormulaLocal と同様の Cell.FormulaLocal を実装します。

考えられる使用シナリオ

Microsoft Excel の数式は、ロケール、地域、言語によって名前が異なる場合があります。例えば、関数が呼び出されますSUMMEドイツ人Aspose.Cells は、英語以外の関数名では機能しません。のMicrosoft エクセル VBA、 がある* *a*Range.FormulaLocal*言語または地域ごとに関数の名前を返すプロパティ。 Aspose.Cellsも提供していますCell.FormulaLocalこの目的のためのプロパティ。ただし、このプロパティは、実装する場合にのみ機能します[GlobalizationSettings.getLocalFunctionName(String standardName)](https://reference.aspose.com/cells/java/com.aspose.cells/globalizationsettings#getLocalFunctionName(java.lang.String)) 方法。

Excel VBA Range.FormulaLocal と同様の Cell.FormulaLocal を実装します。

次のサンプル コードでは、実装方法について説明します。[GlobalizationSettings.getLocalFunctionName(String standardName)](https://reference.aspose.com/cells/java/com.aspose.cells/globalizationsettings#getLocalFunctionName(java.lang.String)) 方法。このメソッドは、標準関数のローカル名を返します。標準関数名が、それを返しますUserFormulaLocal_SUM.必要に応じてコードを変更し、正しいローカル関数名を返すことができます。SUMMEドイツ人文章ТЕКСТロシア.以下のサンプル コードのコンソール出力も参照してください。

サンプルコード

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

コンソール出力

 Formula Local: =UserFormulaLocal_SUM(A1:A2)

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