Obtenga el valor de cadena Cell con y sin formato
Contents
[
Hide
]
Aspose.Cells proporciona un método[Cell.getStringValue()](https://reference.aspose.com/cells/java/com.aspose.cells/cell#getStringValue(int) que se puede usar para obtener el valor de cadena de la celda con o sin formato. Suponga que tiene una celda con valor 0.012345 y la ha formateado para mostrar solo dos lugares decimales. Luego se mostrará como 0.01 en Excel. Puede recuperar valores de cadena como 0.01 y como 0.012345 usando elCell.getStringValue() método. Se necesitaCellValueFormatoEstrategiaenum como un parámetro que tiene los siguientes valores
Obtenga el valor de cadena Cell con y sin formato
El siguiente código de ejemplo explica el uso deCell.getStringValue() método.
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); |
Salida de consola
A continuación se muestra la salida de la consola del código de ejemplo anterior.
0.01
0.012345