Ottieni il valore della stringa della cella con la strategia di formattazione
Aspose.Cells for Python via .NET fornisce un metodo Cell.get_string_value(format_strategy) che può essere utilizzato per ottenere il valore della stringa della cella con o senza formattazione. Supponiamo che tu abbia una cella con valore 0.012345 e l’abbia formattata per visualizzare solo due cifre decimali. Visualizzerà quindi come 0.01 in Excel. Puoi recuperare i valori della stringa sia come 0.01 che come 0.012345 utilizzando il metodo Cell.get_string_value(format_strategy). Richiede come parametro l’enum CellValueFormatStrategy che ha i seguenti valori
- CellValueFormatStrategy.CELL_STYLE
- CellValueFormatStrategy.DISPLAY_STYLE
- CellValueFormatStrategy.DISPLAY_STRING
- CellValueFormatStrategy.NONE
Il seguente codice di esempio spiega l’uso del metodo 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) |