Epplus number of drop down items limitation in excel file

萝らか妹 提交于 2019-11-29 21:37:14

问题


Consider this code:

var dropDown = sheet.DataValidations.AddListValidation(cells[2, colIndex, maxCol, colIndex].Address);
                foreach (var bb in brokerBranchs)
               {
                    dropDown.Formula.Values.Add(bb.Title);
                }

With 29 of dropDown items everything is ok and created excel file works fine but as the number of items exceeds 29, opening created file shows following error:

Opening corrupted result file discards all drop down items associated with all columns. What is possible solution to this problem? Any help will be appreciated.

回答1:


you must add new sheet to add drop down item insert to this sheet

 ExcelWorksheet ddList = excelPackage.Workbook.Worksheets.Add("DropDownList");

now add data to ddList in first column

 var brokerBranchs = accountingUnitOfWork.BrokerServiceAccessor.GetBrokerBranchByBrokerId(firmId).OrderBy(x => x.Title).ToList();
            var val = sheet.DataValidations.AddListValidation(cells[2, colIndex, maxCol, colIndex].Address);
            for (int index = 1; index <= brokerBranchs.Count; index++)
            {
                ddList.Cells[index, 1].Value = brokerBranchs[index - 1].Title;
            }

now create address for use in formula

var address = ddList.Cells[1, 1, brokerBranchs.Count(), 1].Address.ToString();
var arr = address.Split(':');
var char1 = arr[0][0];
var num1 = arr[0].Trim(char1);
var char2 = arr[1][0];
var num2 = arr[1].Trim(char2);

now use address in formula

val.Formula.ExcelFormula = string.Format("=DropDownList!${0}${1}:${2}${3}", char1,          num1, char2, num2);
val.ShowErrorMessage = true;
val.Error = "Select from List of Values ...";


来源:https://stackoverflow.com/questions/20259692/epplus-number-of-drop-down-items-limitation-in-excel-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!