Aspose.Cells で FormulaText 関数を使用する
Contents
[
Hide
]
数式テキストExcel 2013 以降の関数です。 Excel 2010 や 2007 などの以前のバージョンではサポートされていません。その名前が示すように、特定のセルに存在する数式のテキストを出力します。この記事では、Aspose.Cells を使用してこの機能を利用する方法を紹介します。
Aspose.Cells で FormulaText 関数を使用する
次のサンプル コードは、数式テキストこのコードは、最初にセル A1 に数式を書き込み、次に数式のテキストを次のように出力します。数式テキストセル A2 にあります。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
String dataDir = Utils.getDataDir(UsingFormulaTextfunction.class); | |
// Create a workbook object | |
Workbook workbook = new Workbook(); | |
// Access first worksheet | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
// Put some formula in cell A1 | |
Cell cellA1 = worksheet.getCells().get("A1"); | |
cellA1.setFormula("=Sum(B1:B10)"); | |
// Get the text of the formula in cell A2 using FORMULATEXT function | |
Cell cellA2 = worksheet.getCells().get("A2"); | |
cellA2.setFormula("=FormulaText(A1)"); | |
// Calculate the workbook | |
workbook.calculateFormula(); | |
// Print the results of A2. It will now print the text of the formula inside cell A1 | |
System.out.println(cellA2.getStringValue()); |
コンソール出力
上記のサンプル コードのコンソール出力を次に示します。
=SUM(B1:B10)