Search code examples
excel-dna

Excel-dna getting percentage values


I ran into a problem when trying to get percentage values from excel using ExcelReference.getValues(). For 300% it comes back as 3.0 and so on.

Is there any way to distinguish if the value was percentage and formatted to number?

The problem is similar to this one how to convert user input to string in Excel-DNA although it's more formatting problem than calculating formula


Solution

  • You can use the C API GET.CELL information function to get the formatted value of the cell, using info type 53. It returns: "Contents of the cell as it is currently displayed, as text, including any additional numbers or symbols resulting from the cell's formatting."

    object contents = XlCall.Excel(XlCall.xlfGetCell, 53, theReference);