Obtener el valor de cadena de la celda con estrategia de formato
Aspose.Cells para Python via .NET proporciona un método Cell.get_string_value(format_strategy) que se puede utilizar para obtener el valor de cadena de la celda con o sin formato. Supongamos que tienes una celda con el valor 0.012345 y lo has formateado para mostrar solo dos decimales. Entonces se mostrará como 0.01 en Excel. Puedes recuperar los valores de cadena tanto como 0.01 como 0.012345 utilizando el método Cell.get_string_value(format_strategy). Toma como parámetro un CellValueFormatStrategy enum que tiene los siguientes valores
- CellValueFormatStrategy.CELL_STYLE
- CellValueFormatStrategy.DISPLAY_STYLE
- CellValueFormatStrategy.DISPLAY_STRING
- CellValueFormatStrategy.NONE
El siguiente código de ejemplo explica el uso del método Cell.get_string_value(format_strategy).
from aspose.cells import CellValueFormatStrategy, Workbook | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# Create workbook | |
workbook = Workbook() | |
# Access first worksheet | |
worksheet = workbook.worksheets[0] | |
# Access cell A1 | |
cell = worksheet.cells.get("A1") | |
# Put value inside the cell | |
cell.put_value(0.012345) | |
# Format the cell that it should display 0.01 instead of 0.012345 | |
style = cell.get_style() | |
style.number = 2 | |
cell.set_style(style) | |
# Get string value as Cell Style | |
value = cell.get_string_value(CellValueFormatStrategy.CELL_STYLE) | |
print(value) | |
# Get string value without any formatting | |
value = cell.get_string_value(CellValueFormatStrategy.NONE) | |
print(value) |