CellFormat.7z (5.8 KB)
Excel.png (31.2 KB)
In Microsoft Excel, the values displayed in the grid are ‘2026/3/11 0:00’ and ‘8.00%’, but in the edit box, they appear as ‘2026/3/11 0:00:00’ and ‘8%’. I want to retrieve the value as shown in the edit box.
Here is my code:
Workbook wb = new Workbook(@“CellFormat.xlsx”);
Worksheet ws = wb.Worksheets[0];
Console.WriteLine(ws.Cells[0, 0].GetStringValue(CellValueFormatStrategy.CellStyle));
Console.WriteLine(ws.Cells[0, 1].GetStringValue(CellValueFormatStrategy.CellStyle));
I have tried all the enum values in CellValueFormatStrategy, but none of them gives the result I need.
@Jason_Wang
You want to retrieve cell values as they appear in Excel’s edit box, which may differ from the grid display or raw cell value due to formatting . You’ve tried all CellValueFormatStrategy options but none matched your needs .
Unfortunately, Aspose.Cells does not provide a direct method to fetch the exact formatted string as seen in Excel’s edit box . The CellValueFormatStrategy enumeration does not include an option for this specific formatting behavior . To achieve the desired result, you would need to manually apply the cell’s number format using the NumberFormat property and format the underlying numeric value accordingly, possibly requiring custom logic .
Since you’re working with a specific Excel file and its formatting, you might need to inspect the cell’s NumberFormat property and apply it manually to the cell’s value to match the edit box display .
@Jason_Wang
Please get string value in edit box as the following :
public static string GetStringValueInEditBox(Cell cell)
{
if (cell == null)
return null;
// Get cell data type
CellValueType cellType = cell.Type;
switch (cellType)
{
// 3. Numeric value (integer/decimal/currency, etc.)
case CellValueType.IsNumeric:
double numericValue = cell.DoubleValue;
Style style = cell.GetStyle();
if(style.Number == 9
|| style.Number == 10
|| style.Custom.IndexOf("%") != -1)
{
return numericValue.ToString("#%");
}
return numericValue.ToString();
// 5. DateTime
case CellValueType.IsDateTime:
DateTime dateValue = cell.DateTimeValue;
return dateValue.ToString();
default:
return cell.StringValue;
}
}