触发场景描述 下拉框数据,String[]中包含的所有文本长度超过255 触发Bug的代码
/**
* SheetWriteHandler的实现类
*/
public class TemplateSheetWriteHandler implements SheetWriteHandler {
/**
* 下拉框选项1
*/
private String[] theFirst;
// 构造函数
public TemplateSheetWriteHandler(String[] theFirst,String[] theSecond) {
// 异常数据
this.theFirst = new String[]{"1:测试01","2:测试02","14:大众","15:123","16:测试33","17:cs","18:车系12","19:测试12","20:shell","21:1","22:2113","23:22222","24:4","25:测试11","26:kw-series","27:kw-series","28:yugu","29:ceshi","30:车系车","31:车系车型","32:3333444","33:yugu","34:车系","35:极光","36:相同车系141","37:HH","38:JJ","39:LL","40:114新增车系","41:114新增车系2edit4","42:444444","43:55555"};
// 正常数据
// this.theFirst = new String[]{"1:测试01","15:123","17:cs","20:shell","23:22222","24:4","26:kw-series","27:kw-series","28:yugu","32:3333444","33:yugu","34:车系","35:极光","36:相同车系141","37:HH","40:114新增车系","41:114新增车系2edit4","42:444444","43:55555"};
}
@Override
public void beforeSheetCreate(WriteWorkbookHolder writeWorkbookHolder, WriteSheetHolder writeSheetHolder) {
}
@Override
public void afterSheetCreate(WriteWorkbookHolder writeWorkbookHolder, WriteSheetHolder writeSheetHolder) {
LOGGER.info("第{}个Sheet写入成功。", writeSheetHolder.getSheetNo());
// 区间设置 第一列第一行和第二行的数据。由于第一行是头,所以第一、二行的数据实际上是第二三行
DataValidationHelper helper = writeSheetHolder.getSheet().getDataValidationHelper();
// theFirst
if (ArrayUtils.isNotEmpty(theFirst)) {
CellRangeAddressList cellRangeAddressList = new CellRangeAddressList(1, 1000, 0, 0);
DataValidationConstraint constraint = helper.createExplicitListConstraint(theFirst);
DataValidation dataValidation = helper.createValidation(constraint, cellRangeAddressList);
writeSheetHolder.getSheet().addValidationData(dataValidation);
}
}
}
提示的异常或者没有达到的效果 文件打开提示”部分内容有问题“