外协人员excel导入优化

This commit is contained in:
2025-12-18 09:27:45 +08:00
parent 235b95a653
commit 4b45b69291
12 changed files with 1697 additions and 53 deletions

View File

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

View File

@@ -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列