实施 Cell.FormulaLocal 类似于 Excel VBA Range.FormulaLocal

可能的使用场景

Microsoft Excel 公式在不同的语言环境或地区或语言中可能有不同的名称。例如,函数被调用夏日德语Aspose.Cells 无法使用非英语函数名称。在Microsoft Excel VBA, 有* *一种*范围.FormulaLocal*根据函数的语言或区域返回函数名称的属性。 Aspose.Cells还提供Cell.FormulaLocal为此目的的财产。但是,此属性仅在您实施时才有效[GlobalizationSettings.getLocalFunctionName(字符串标准名称)](https://reference.aspose.com/cells/java/com.aspose.cells/globalizationsettings#getLocalFunctionName(java.lang.String)) 方法。

实施 Cell.FormulaLocal 类似于 Excel VBA Range.FormulaLocal

下面的示例代码解释了如何实现[GlobalizationSettings.getLocalFunctionName(字符串标准名称)](https://reference.aspose.com/cells/java/com.aspose.cells/globalizationsettings#getLocalFunctionName(java.lang.String)) 方法。该方法返回标准函数的本地名称。如果标准函数名是它返回UserFormulaLocal_SUM.您可以根据需要更改代码并返回正确的本地函数名称,例如夏日德语文本ТЕКСТ俄语.另请参阅下面给出的示例代码的控制台输出以供参考。

示例代码

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