Spire.XLS is a professional Excel API that enables developers to create, manage, manipulate, convert and print Excel worksheets. Get free and professional technical support for Spire.XLS for .NET, Java, Android, C++, Python.

Mon Jan 03, 2022 11:43 pm

I'm using Spire.XLS with .NET.
Is there a way to set the max number of characters for a cell? I only want a cell to allow 50 characters.

I've seen CellDataType.TextLength but I'm not sure how to set the max length.

surfdmountain
 
Posts: 8
Joined: Wed Dec 15, 2021 9:49 pm

Tue Jan 04, 2022 2:28 am

Hello,

Thanks for your inquiry!

Please refer to the following code to set the max length of the cell. If you have any other questions, just feel free to contact us.

Code: Select all
            //set the length <= 5
            Workbook workbook = new Workbook();
            Worksheet worksheet = workbook.Worksheets[0];
            CellRange cellA1 = worksheet["A1"];
            cellA1.DataValidation.AllowType = CellDataType.TextLength;
            cellA1.DataValidation.CompareOperator = ValidationComparisonOperator.LessOrEqual;
            cellA1.DataValidation.Formula1 = "5";


Sincerely,
Marcia
E-iceblue support team
User avatar

Marcia.Zhou
 
Posts: 858
Joined: Wed Nov 04, 2020 2:29 am

Tue Jan 04, 2022 9:00 pm

Thanks! That works!

surfdmountain
 
Posts: 8
Joined: Wed Dec 15, 2021 9:49 pm

Wed Jan 05, 2022 1:19 am

Hello,

Thanks for your feedback!

Glad to hear that the code is worked.

If you encounter any issues related to our product in the future, just feel free to contact us.

Have a nice day!

Sincerely,
Marcia
E-iceblue support team
User avatar

Marcia.Zhou
 
Posts: 858
Joined: Wed Nov 04, 2020 2:29 am

Return to Spire.XLS

cron