Ottieni il valore stringa Cell con e senza formattazione
Contents
[
Hide
]
Aspose.Cells fornisce un metodoCell.GetStringValue() che può essere utilizzato per ottenere il valore della stringa della cella con o senza alcuna formattazione. Supponiamo di avere una cella con valore 0,012345 e di averla formattata per visualizzare solo due cifre decimali. Verrà quindi visualizzato come 0,01 in Excel. È possibile recuperare valori di stringa sia come 0,01 che come 0,012345 utilizzando ilCell.GetStringValue() metodo. Ci vuoleCellValueFormatStrategiaenum come parametro che ha i seguenti valori
- CellValueFormatStrategy.CellStyle
- CellValueFormatStrategy.DisplayStyle
- CellValueFormatStrategy.None
Il seguente codice di esempio spiega l’uso diCell.GetStringValue()metodo.
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-.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); |