書式設定あり/なしで Cell 文字列値を取得する
Contents
[
Hide
]
Aspose.Cells はメソッドを提供します[Cell.getStringValue()](https://reference.aspose.com/cells/java/com.aspose.cells/cell#getStringValue(int) を使用して、書式設定の有無にかかわらず、セルの文字列値を取得できます。値が 0.012345 のセルがあり、小数点以下 2 桁のみを表示するように書式設定したとします。 Excel では 0.01 と表示されます。を使用して、文字列値を 0.01 と 0.012345 の両方として取得できます。[Cell.getStringValue()](https://reference.aspose.com/cells/java/com.aspose.cells/cell#getStringValue(int) ) 方法。それはとりますCellValueFormat戦略次の値を持つパラメーターとしての列挙型
書式設定あり/なしで Cell 文字列値を取得する
次のサンプル コードは、[Cell.getStringValue()](https://reference.aspose.com/cells/java/com.aspose.cells/cell#getStringValue(int)) 方法。
This file contains 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 | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(GetCellStringValue.class); | |
// Create workbook | |
Workbook workbook = new Workbook(); | |
// Access first worksheet | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
// Access cell A1 | |
Cell cell = worksheet.getCells().get("A1"); | |
// Put value inside the cell | |
cell.putValue(0.012345); | |
// Format the cell that it should display 0.01 instead of 0.012345 | |
Style style = cell.getStyle(); | |
style.setNumber(2); | |
cell.setStyle(style); | |
// Get string value as Cell Style | |
String value = cell.getStringValue(CellValueFormatStrategy.CELL_STYLE); | |
System.out.println(value); | |
// Get string value without any formatting | |
value = cell.getStringValue(CellValueFormatStrategy.NONE); | |
System.out.println(value); |
コンソール出力
以下は、上記のサンプル コードのコンソール出力です。
0.01
0.012345