外协人员excel导入优化
This commit is contained in:
@@ -45,8 +45,19 @@ public class CustomSheetWriteHandler implements SheetWriteHandler {
|
||||
}
|
||||
|
||||
for (Map.Entry<Integer, List<String>> entry : dropDownData.entrySet()){
|
||||
if(entry.getValue().size()>=10){
|
||||
String[] selectValues = entry.getValue().toArray(new String[entry.getValue().size()]);
|
||||
List<String> values = entry.getValue();
|
||||
// 计算下拉框所有选项的字符总数(包括分隔符逗号)
|
||||
int totalLength = 0;
|
||||
for (String value : values) {
|
||||
totalLength += value != null ? value.length() : 0;
|
||||
}
|
||||
// 加上分隔符(逗号)的长度,如果有n个选项,需要n-1个逗号
|
||||
if (values.size() > 1) {
|
||||
totalLength += values.size() - 1;
|
||||
}
|
||||
// 如果字符总数超过255,或者选项数量>=10,创建隐藏sheet用于sheet引用
|
||||
if (totalLength > 255 || values.size() >= 10) {
|
||||
String[] selectValues = values.toArray(new String[values.size()]);
|
||||
/* 解决办法从这里开始 */
|
||||
//获取一个workbook
|
||||
Workbook workbook = writeWorkbookHolder.getWorkbook();
|
||||
|
||||
@@ -110,15 +110,25 @@ public class RowFormatSetTextHandler implements CellWriteHandler {
|
||||
|
||||
String[] dropdownOptionsArray = dropdownOptionList.toArray(new String[0]);
|
||||
|
||||
// 计算下拉框所有选项的字符总数(包括分隔符逗号)
|
||||
int totalLength = 0;
|
||||
for (String value : dropdownOptionList) {
|
||||
totalLength += value != null ? value.length() : 0;
|
||||
}
|
||||
// 加上分隔符(逗号)的长度,如果有n个选项,需要n-1个逗号
|
||||
if (dropdownOptionList.size() > 1) {
|
||||
totalLength += dropdownOptionList.size() - 1;
|
||||
}
|
||||
|
||||
// 创建下拉列表的约束
|
||||
DataValidationConstraint constraint;//= helper.createExplicitListConstraint(dropdownOptionsArray);
|
||||
if (dropdownOptionsArray.length < 10) {
|
||||
DataValidationConstraint constraint;
|
||||
// 如果字符总数超过255,或者选项数量>=10,使用sheet引用方式
|
||||
if (totalLength > 255 || dropdownOptionsArray.length >= 10) {
|
||||
// 联动到另外一个 sheet
|
||||
constraint = helper.createFormulaListConstraint("hidden"+firstCol+"!$A$1:$A$"+dropdownOptionList.size());
|
||||
} else {
|
||||
// 直接设置下拉选
|
||||
constraint = helper.createExplicitListConstraint(dropdownOptionsArray);
|
||||
} else {
|
||||
// 联动到另外一个 sheet
|
||||
//这里如果识别到大于等于10行不管数据量有多少
|
||||
constraint = helper.createFormulaListConstraint("hidden"+firstCol+"!$A$1:$A$"+dropdownOptionList.size());
|
||||
}
|
||||
|
||||
// 设置下拉列表应用的单元格区域,例如第2行到最后一行的第2列
|
||||
|
||||
Reference in New Issue
Block a user