Obtener el valor de cadena de la celda con o sin formato
Aspose.Cells proporciona un método Cell.GetStringValue() que se puede usar para obtener el valor de cadena de la celda con o sin ningún formato. Suponga que tiene una celda con el valor 0.012345 y lo ha formateado para mostrar solo dos decimales. Entonces se mostrará como 0.01 en Excel. Puede recuperar los valores de cadena tanto como 0.01 como 0.012345 utilizando el método Cell.GetStringValue(). Toma un parámetro de tipo CellValueFormatStrategy enum que tiene los siguientes valores
- CellValueFormatStrategy.CellStyle
- CellValueFormatStrategy.DisplayStyle
- CellValueFormatStrategy.DisplayString
- CellValueFormatStrategy.None
El siguiente código de ejemplo explica el uso del método Cell.GetStringValue().
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// Create workbook | |
Workbook workbook = new Workbook(); | |
// Access first worksheet | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Access cell A1 | |
Cell cell = worksheet.Cells["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.Number = 2; | |
cell.SetStyle(style); | |
// Get string value as Cell Style | |
string value = cell.GetStringValue(CellValueFormatStrategy.CellStyle); | |
Console.WriteLine(value); | |
// Get string value without any formatting | |
value = cell.GetStringValue(CellValueFormatStrategy.None); | |
Console.WriteLine(value); |