代码如下:
XSSFWorkbook wb = new XSSFWorkbook();
ISheet sheet1 = wb.CreateSheet("Sheet1");
CellRangeAddressList regions = new CellRangeAddressList(0, 65535, 0, 0);
XSSFDataValidationConstraint xssConstraint = new XSSFDataValidationConstraint(new string[] { "itemA", "itemB", "itemC" });
CT_DataValidation c = new CT_DataValidation();
XSSFDataValidation dataValidate = new XSSFDataValidation(xssConstraint, regions, c);
sheet1.AddValidationData(dataValidate);
但是测试发现下拉菜单没有生成,请大家帮忙指导下。谢谢。
.net中NPOI在.xls后缀和.xlsx后缀的excel中创建下拉菜单的问题
下面这段代码在.xls后缀的excel中可以创建下拉菜单
CellRangeAddressList regions = new CellRangeAddressList(i + 1, 65535, j, j);
DVConstraint constraint = DVConstraint.CreateExplicitListConstraint(list);
HSSFDataValidation dataValidate = new HSSFDataValidation(regions, constraint);
sheet.AddValidationData(dataValidate);
但是下面这段代码在.xlsx后缀的excel中为什么不能创建下拉菜单啊?麻烦大家指导下。
CellRangeAddressList regions = new CellRangeAddressList(i + 1, 65535, j, j);
XSSFDataValidationConstraint constraint = new XSSFDataValidationConstraint(list);
CT_DataValidation cdv = new CT_DataValidation();
cdv.allowBlank = true;
XSSFDataValidation dataValidate = new XSSFDataValidation(constraint, regions, cdv);
sheet.AddValidationData(dataValidate);