Many thanks to Jason for the link to CLOSED XML: Conditional Formatting!
Thanks to this I managed to find the way to apply conditional formatting I needed:
cell.AddConditionalFormat()
.WhenEquals(
string.Format(
"=TRUNC(${0}${1})",
cell.WorksheetColumn().ColumnLetter(),
cell.WorksheetRow().RowNumber()))
.NumberFormat
.Format = "general\"%\"";
I gave up using percent format specifier, as it makes me divide by 100. From Excel Custom Number Formats:
% Percentage. Microsoft Excel multiplies by 100 and adds the % character.
Now I simply add %
as a string, not as a format specifier.
So the main number format is 0.##\"%\"
, but when the value's decimal part is zero, I substitute the number format to the general one with %
in the end using conditional formatting.