Free Support Forum - aspose.com

Number format issue: Only numbers to enter/ control of decimal places

Hi,

I need to set the number format of a certain cellrange to "0.00" so I set style.Numberformat=2. However, I was still able to enter letters...I think that should not be. There should be an option where only entries of numbers are allowed. There should be further options to control the number of decimals...how to enter a number like 1.001 or 3.0327182 ? Again, number format "General" would not work as only numbers should be allowed to enter.

I think number format should work like in Excel, but it seems it does not. Is there a trick?

Oliver

Hi Oliver,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for considering Aspose.

Well, I think you may use the Validation option to get your desired results. Please see the following sample code:

Worksheet.Validations.Add("A4", true, @"^\d{1,3}(\.\d{0,7})?$");

Thank You & Best Regards,

Thanks. It indeed control the data entry, but I do not want the validation message to come up all the time. Other than number keys should be locked for data entry (and beep would be nice to have so user is aware of wrong entry).

Your solution gives me also only the possibility to enter 0.00 numbers, for example 2.001 is turned automatically to 2.00. I need the grid for a statistic application, where numbers with 4 or more decimals are typical. The user should able to set how many numbers after deimal point is displayed.

Hi,

Please try the attached version v2.0.1.25. We now provide an event named CellValidationFailed in v<?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" />2.0.1.25. You can handle this event and set e.Handled = true to prevent showing the ValidationFailed MessageBox and add your beep function.<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

You can set Style.Custom = “0.###” to display your numbers in the format i.e.., 2.001.

Thank you.

Thanks for quick solution, which works fine. May be for a future release, it would be nice just to block the "letters" key, as in the current solution the user still can type letters. But that is fine for me now.

For the number format, I used now Style.Custom ="0.###" but if I enter 2.0002 the value turns to 2 and not to 2.000...I know it is a minor thing and it is the same value. But...having a 2 instead of 2.000 in the grid could indicate that the user forgot to enter the decimal places, even so he did not. Something I would like to see in a near future release.

For the sheet.Validation.Add, I tried to apply it for a defined cellrange but it did not work. A solution without using two loops to run through the number of columns and rows?

Oliver

Hi Oliver,

Regarding number format, MS Excel shows it "2." where as Aspose.Grid.Desktop shows as "2". We always follow MS Excel standards, don't you think it should function in MS Excel's way?

For applying a custom style formatting to a CellRange, it works fine. Following is my test code that works fine.

Dim cellrange As New Aspose.Grid.Desktop.CellRange(0, 0, 5, 3)

Dim style1 As Aspose.Grid.Desktop.Style = New Style(GridDesktop1)

style1.Custom = "0.###"

GridDesktop1.Worksheets(0).SetStyle(cellrange, style1)

If you still find the issue, kindly give us more details with sample code to reproduce the issue, we will check it soon.

Thank you.

Hi Oliver,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for considering Aspose.

For the number format, you can customize it like “<?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" />0.000”, “0.###0” etc. Please see the following msdn documentation link for further details regarding “Custom Numeric Format Strings”,

http://msdn.microsoft.com/en-us/library/0c899ak8.aspx

Thank You & Best Regards,

It is working fine now. Thanks again

Hi

We have some word document using numeric format strings like this :

\# # ##0,00;(# ##0,00)

In French version of MSWord, this format string works fine.
But with aspose, using "," instead "." seems to be a problem.

Is there any way to support numeric format string containing "," instead of "." with Aspose.Word ?

Thanks for help

Maxime

Hi

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your inquiry. Maybe in your case you can just specify culture of the thread, when you processing document. See the following code:

// Change culture of the currnt thread.

CultureInfo currentCulture = Thread.CurrentThread.CurrentCulture;

Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");

// Here is your mail merge staff.

// Change culture back.

Thread.CurrentThread.CurrentCulture = currentCulture;

Hope this helps.

Best regards.