DisplayStringValue api does not work

hi ,

1.zip (6.3 KB)

i have a excel file ,the display string value of A1 cell in first worksheet should be 0.0000

but the “DisplayStringValue” api returns -0.0000

my codes :

var cell = worksheet.Cells[“A1”];
if (cell == null) return “”;
if (string.IsNullOrEmpty(cell.DisplayStringValue)) return “”;
var value = cell.DisplayStringValue;
return value

@vs6060_qq_com

It seems that you are encountering an issue with the DisplayStringValue API returning -0.0000 instead of the expected 0.0000. This behavior has been noted by other users as well.

One possible reason for this discrepancy could be related to how the value is formatted or represented in the Excel file. In some cases, the API may return a negative zero (-0.0) due to the underlying representation of the number in the Excel file.

To troubleshoot this issue, you can try the following steps:

  1. Check the Excel File: Ensure that the value in cell A1 is indeed formatted correctly in Excel. Sometimes, the formatting in Excel can affect how values are read by the API.

  2. Update Aspose.Cells: If you are using an older version of Aspose.Cells, consider updating to the latest version. Users have reported that the issue was resolved in newer releases. For example, a user tested their scenario with Aspose.Cells for .NET v24.3 and found that it worked as expected, returning 0.0 instead of -0.0.

  3. Sample Code: Here is a sample code snippet that you can use to retrieve the display string value of a cell:

    var workbook = new Workbook("path_to_your_excel_file.xlsx");
    var sheet = workbook.Worksheets[0]; // Access the first worksheet
    var cell = sheet.Cells["A1"]; // Access cell A1
    var value = cell.DisplayStringValue; // Get the display string value
    Console.WriteLine(value); // Output the value
    
  4. Consider Formatting: If the issue persists, you might want to check the cell’s formatting and ensure that it is set to display the value as you expect.

If you continue to experience issues, please provide additional details about the version of Aspose.Cells you are using and any specific formatting applied to the cell in question.

Sources:
[1]: Cell.displaystringvalue seems not working
[2]: Cell.displaystringvalue seems not working

@vs6060_qq_com
We can obtain the correct results by testing on the latest version v24.12 using the following sample code.

Console.WriteLine("version: " + CellsHelper.GetVersion());
// Load the Excel file
Workbook workbook = new Workbook(filePath + "1.xlsx");

// Get the first worksheet 
Worksheet worksheet = workbook.Worksheets[0];

Console.WriteLine(worksheet.Cells["A1"].DisplayStringValue);

The output as follows:

version: 24.12
0.0000

We recommend you to kindly try using our latest version:
Aspose.Cells for .NET 24.12.

hi John,

you are right,when i upgraded aspose.cells to latest version, the issue was gone.

thank you very much.

@vs6060_qq_com,

You’re welcome! It’s great to hear that upgrading to a newer version of Aspose.Cells for .NET resolved your issue. Please don’t hesitate to reach out if you have any more questions or feedback.