We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Getting DecimalPlaces for formula cells

Thread ID:





67608 Aug 24,2007 03:15 PM UTC Aug 29,2007 10:47 AM UTC WinForms 5
Tags: XlsIO
Christian Muirhead
Asked On August 24, 2007 03:15 PM UTC

Hi -

In this workbook A1 contains a constant number and is set to display 3 decimal places, while B1 has a formula (=1/3), and is set to display 5 decimal places.

I can get the decimal places for A1 using:

wb.ActiveSheet[1, 1].CellStyle.NumberFormatSettings.DecimalPlaces

but trying the same thing with B1 (wb.ActiveSheet[1, 2]...) fails with a NullReferenceException.

I'm reluctant to parse the CellStyle.NumberFormat string (especially given that I'm having trouble finding a detailed description of what it might contain).

Any ideas what might be going on here?



Sarathi D [Syncfusion]
Replied On August 25, 2007 12:36 AM UTC

Hi Christian,

Thank you for posting your query to us.

We are able to reproduce the issue here. One way you can work-around this issue by using the below code snippet.

string s = sheet.Range["B1"].CellStyle.NumberFormatSettings.FormatString;
int l = s.Length - 2;

Please refer to the attached sample for implementation and let me know if this helps.



Konrad Delong
Replied On August 28, 2007 10:31 AM UTC

After spending some time on the issue, whe ended up parsing format string, as you suggest.

However, the solution doesn't work for cells with alternative formatting for negatives whose format string look like this:


Do you happen to have full formatString specification?

Sarathi D [Syncfusion]
Replied On August 29, 2007 12:34 AM UTC

Hi Christian,

I am afraid that I was not able to reproduce the issue again.I have applied alternate formatting to the cells but I am not able to see the issue.
I have attached the sample which I have worked and it is available here.


Please have a look at the above sample and if still the issue exists, could you please try reproducing it
in the above sample or send us the reproducing steps so that we could sort out the cause of the issue
and provide you a solution?

A sample from you will help a lot to reproduce the issue.

Sorry for the inconvenience.


Konrad Delong
Replied On August 29, 2007 10:40 AM UTC

Whoops, seems like I answered to wrong thread...


Konrad Delong
Replied On August 29, 2007 10:47 AM UTC

OK, sorry once againg for mess on forum threads.

Format string may contain up to 4 sections defining formatting for positive, negative, zero and text data. What's more: they can describe date, time and fraction formatting. It's a legacy excel feature of course, but unfortunately many excel documents take advantage of this, which means that we cannot simply take the length of format string and subtract 2.

Some examples of valid format strings:

General <- yes, this one too

Hope the attached example will be of some help.



This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

or the page will be automatically redirected to sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon