Holen Sie sich Cell Zeichenfolgenwert mit und ohne Formatierung
Contents
[
Hide
]
Aspose.Cells stellt eine Methode bereitCell.getStringValue(), die verwendet werden kann, um den Zeichenfolgenwert der Zelle mit oder ohne Formatierung abzurufen. Angenommen, Sie haben eine Zelle mit dem Wert 0,012345 und Sie haben sie so formatiert, dass nur zwei Dezimalstellen angezeigt werden. Es wird dann in Excel als 0,01 angezeigt. Sie können Zeichenfolgenwerte sowohl als 0,01 als auch als 0,012345 abrufen, indem Sie die verwendenCell.getStringValue() Methode. Es brauchtCellValueFormatStrategieenum als Parameter, der die folgenden Werte hat
Holen Sie sich Cell Zeichenfolgenwert mit und ohne Formatierung
Der folgende Beispielcode erläutert die Verwendung vonCell.getStringValue() Methode.
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); |
Konsolenausgabe
Unten ist die Konsolenausgabe des obigen Beispielcodes.
0.01
0.012345