Hämta Cell String Value med och utan formatering
Contents
[
Hide
]
Aspose.Cells tillhandahåller en metodCell.GetStringValue() som kan användas för att få strängvärdet för cellen med eller utan någon formatering. Anta att du har en cell med värdet 0,012345 och du har formaterat den så att den endast visar två decimaler. Det kommer då att visas som 0.01 i Excel. Du kan hämta strängvärden både som 0,01 och som 0,012345 med hjälp avCell.GetStringValue() metod. Det tarCellValueFormatStrategyenum som en parameter som har följande värden
- CellValueFormatStrategy.CellStyle
- CellValueFormatStrategy.DisplayStyle
- CellValueFormatStrategy.None
Följande exempelkod förklarar användningen avCell.GetStringValue()metod.
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); |