Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Locale on conditionalcolor scale #520

Closed
trykyn opened this issue Feb 16, 2021 · 3 comments
Closed

Locale on conditionalcolor scale #520

trykyn opened this issue Feb 16, 2021 · 3 comments
Labels
Milestone

Comments

@trykyn
Copy link

trykyn commented Feb 16, 2021

When creating a color scale conditional formatting with explicit numbers, the locale seems to matter and invalid numbers get exported when using e.g. german number format

colorScaleFormatting.Thresholds[0].RangeType = RangeType.NUMBER; colorScaleFormatting.Thresholds[0].Value = -0.3; colorScaleFormatting.Thresholds[1].RangeType = RangeType.NUMBER; colorScaleFormatting.Thresholds[1].Value = 0.0; colorScaleFormatting.Thresholds[2].RangeType = RangeType.NUMBER; colorScaleFormatting.Thresholds[2].Value = 0.3;

Invalid output in the xml:
<conditionalFormatting sqref="E5"> <cfRule type="colorScale" dxfId="0" priority="1" aboveAverage="1"> <colorScale> <cfvo type="num" val="-0,3" gte="1" /> <cfvo type="num" val="0" gte="1" /> <cfvo type="num" val="0,3" gte="1" /> <color indexed="12" /> <color indexed="9" /> <color indexed="10" /> </colorScale> </cfRule> </conditionalFormatting>

@delreluca
Copy link

delreluca commented Apr 7, 2021

I haven't dug deep, but I think that the issue is the following parameterless ToString call:

@tonyqus
Copy link
Member

tonyqus commented Apr 17, 2021

What's your CultureInfo of the thread? German?

@delreluca
Copy link

Yes, Thread.CurrentThread.CurrentCulture is de-DE, but it happens with every culture that doesn't use . as decimal separator (e.g. fr-FR, it-IT, …).

So in the above mentioned line

replacing value.ToString() by value.ToString(CultureInfo.InvariantCulture) should ensure the correct format independent of the current culture.

Please note that the line in the getter

has to be adjusted as well to double.Parse(cfvo.val, CultureInfo.InvariantCulture) for consistency

@tonyqus tonyqus added the bug label Apr 18, 2021
@tonyqus tonyqus added this to the NPOI 2.5.5 milestone Apr 18, 2021
@tonyqus tonyqus modified the milestones: NPOI 2.5.5, NPOI 2.5.4 Jul 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants