none
How to add validation to specific Columns to only be decimal value using C# RRS feed

  • Question

  • Hi All really need some help.

    I have a spread sheet that is generated through C#. I need specific columns (H through to U) to only contain validation that only accepts decimal values. The number of rows will vary from sheet to sheet as agreements from the supplier varies.

    I pretty sure that I have to remove previous validation applied by using

    range.Validation.delete()

    I then need to add the validation by using

    range.Validation.Add(

                    xl::

    XlDVType.xlValidateDecimal,

                    xl::

    XlDVAlertStyle.xlValidAlertStop,

    );

    I have tried this but the speadsheet won't get generated.

    The above is an example of the sheet. The blue highlighted cells should only contain decimal values

    Many thanks

    Mark

    Tuesday, December 8, 2015 1:24 PM

Answers

  • Hi Mark,

    >> The above is an example of the sheet. The blue highlighted cells should only contain decimal values

    Based on your code, you did not define parameters for Formula1 and Formula2. With the link below, one of either FOrumula1 or Formula2 must be specified or both may be specified when you use xlValidateDecimal.

    # Add Method
    https://msdn.microsoft.com/en-us/library/microsoft.office.interop.excel.validation.add(v=office.14).aspx

    Here is a simple code:

                Worksheet ws = wk.ActiveSheet;
                Range r = ws.Range["C4"];
                r.Validation.Add( XlDVType.xlValidateDecimal, XlDVAlertStyle.xlValidAlertStop, XlFormatConditionOperator.xlBetween, "0", "100");

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Wednesday, December 9, 2015 8:06 AM