How to fix the issue regarding the limit of 256 characters in data validation in excel

Deepak Kumar Swain 0 Reputation points
2024-07-01T07:44:04.9733333+00:00

Hi,

I am directly inputting values from code base on to the drop-down list using data validation, where facing issues while opening the excel file.

Where have notice if the total characters of the list of dropdowns is within 256 characters, am able to open the excel file without the recovery window.

Code examples:

Workbook _workbook = new Workbook();

var dataWorksheet = _workbook.Worksheets["Sheet1"];

System.Collections.Generic.List<string> longTexts = new System.Collections.Generic.List<string>(); longTexts.Add("This is the test(IND) Rs: 10923.00 rupees.");

longTexts.Add("This is the test(US)$124.00 rupees.");

longTexts.Add("This is the test(US)$125.00 rupees.");

longTexts.Add("This is the test(US)$126.00 rupees.");

longTexts.Add("This is the test(US)$127.00 rupees.");

longTexts.Add("This is the test(US)$128.00 rupees.");

longTexts.Add("This is the test(US)$129.00 rupees.");

longTexts.Add("This is the test(US)$130.00 rupees.");

longTexts.Add("This is the test(US)$131.00 rupees.");

longTexts.Add("This is the test(US)$132.00 rupees.");

CellArea area = new CellArea();

var dropdownList = string.Join(",", longTexts.ToArray());

var validations = dataWorksheet.Validations;

var validation = validations[validations.Add(area)];

validation.Type = Aspose.Cells.ValidationType.List;

validation.Operator = OperatorType.Between;

validation.InCellDropDown = true;

validation.Formula1 = dropdownList; area.StartRow = 1;

area.EndRow = 1;

area.StartColumn = 1;

area.EndColumn = 1;

validation.AddArea(area); _workbook.Save("e:\test2\out1.xlsx");

Please help me to identify and resolve the issue.

Excel
Excel
A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.
1,646 questions
Office Development
Office Development
Office: A suite of Microsoft productivity software that supports common business tasks, including word processing, email, presentations, and data management and analysis.Development: The process of researching, productizing, and refining new or existing technologies.
3,680 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Viorel 114K Reputation points
    2024-07-02T09:46:57.9833333+00:00

    Try an alternative: put all of the values to a range (for example: X1:X10). This special column or worksheet can be hidden. Then specify the range in the Source field of Data Validation dialog. If it works manually, then the program should work too.

    0 comments No comments