首页 新闻 会员 周边 捐助

.net中NPOI导出excel07格式(.xlsx)文件时写下拉菜单

0
悬赏园豆:50 [已关闭问题] 关闭于 2016-07-20 16:48

代码如下:

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);

fixbug11的主页 fixbug11 | 初学一级 | 园豆:10
提问于:2016-07-19 14:35
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册