Excel VBAのRange.FormulaLocalに類似したCell.FormulaLocalの実装
可能な使用シナリオ
Microsoft Excelの関数は、異なる地域や言語で異なるロケール名を持つ場合があります。例えば、SUM関数はドイツ語ではSUMMEと呼ばれます。Aspose.Cellsでは、非英語の関数名は使用できません。Microsoft Excel VBAには、関数の名前をその言語や地域に合わせて返すRange.FormulaLocalプロパティがあります。Aspose.Cellsもこの目的のためにCell.FormulaLocalプロパティを提供しています。ただし、このプロパティはGlobalizationSettings.GetLocalFunctionName(string standardName)メソッドを実装している場合にのみ機能します。
Excel VBAのRange.FormulaLocalと同様にCell.FormulaLocalを実装する
以下のサンプルコードは、GlobalizationSettings.GetLocalFunctionName(string standardName)メソッドの実装方法を説明しています。このメソッドは、標準関数のローカル名を返します。標準関数名が SUM の場合、UserFormulaLocal_SUM を返します。SUM はドイツ語では SUMME 、ロシア語では ТЕКСТ となります。必要に応じてコードを変更し、正しいローカル関数名を返してください。また、下記のサンプルコードのコンソール出力も参照してください。
サンプルコード
// 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); | |
} | |
} | |
} |
コンソール出力
Formula Local: =UserFormulaLocal_SUM(A1:A2)
Formula Local: =UserFormulaLocal_AVERAGE(B1:B2,B5)