|
@@ -48,6 +48,7 @@ import org.apache.poi.ss.usermodel.FillPatternType;
|
|
|
import org.apache.poi.ss.usermodel.Font;
|
|
|
import org.apache.poi.ss.usermodel.HorizontalAlignment;
|
|
|
import org.apache.poi.ss.usermodel.IndexedColors;
|
|
|
+import org.apache.poi.ss.usermodel.Name;
|
|
|
import org.apache.poi.ss.usermodel.PictureData;
|
|
|
import org.apache.poi.ss.usermodel.Row;
|
|
|
import org.apache.poi.ss.usermodel.Sheet;
|
|
@@ -982,8 +983,16 @@ public class ExcelUtil<T>
|
|
|
}
|
|
|
if (StringUtils.isNotEmpty(attr.prompt()) || attr.combo().length > 0)
|
|
|
{
|
|
|
-
|
|
|
- setPromptOrValidation(sheet, attr.combo(), attr.prompt(), 1, 100, column, column);
|
|
|
+ if (attr.combo().length > 15 || StringUtils.join(attr.combo()).length() > 255)
|
|
|
+ {
|
|
|
+
|
|
|
+ setXSSFValidationWithHidden(sheet, attr.combo(), attr.prompt(), 1, 100, column, column);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+
|
|
|
+ setPromptOrValidation(sheet, attr.combo(), attr.prompt(), 1, 100, column, column);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -1087,6 +1096,58 @@ public class ExcelUtil<T>
|
|
|
sheet.addValidationData(dataValidation);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ * 设置某些列的值只能输入预制的数据,显示下拉框(兼容超出一定数量的下拉框).
|
|
|
+ *
|
|
|
+ * @param sheet 要设置的sheet.
|
|
|
+ * @param textlist 下拉框显示的内容
|
|
|
+ * @param promptContent 提示内容
|
|
|
+ * @param firstRow 开始行
|
|
|
+ * @param endRow 结束行
|
|
|
+ * @param firstCol 开始列
|
|
|
+ * @param endCol 结束列
|
|
|
+ */
|
|
|
+ public void setXSSFValidationWithHidden(Sheet sheet, String[] textlist, String promptContent, int firstRow, int endRow, int firstCol, int endCol)
|
|
|
+ {
|
|
|
+ String hideSheetName = "combo_" + firstCol + "_" + endCol;
|
|
|
+ Sheet hideSheet = wb.createSheet(hideSheetName);
|
|
|
+ for (int i = 0; i < textlist.length; i++)
|
|
|
+ {
|
|
|
+ hideSheet.createRow(i).createCell(0).setCellValue(textlist[i]);
|
|
|
+ }
|
|
|
+
|
|
|
+ Name name = wb.createName();
|
|
|
+ name.setNameName(hideSheetName + "_data");
|
|
|
+ name.setRefersToFormula(hideSheetName + "!$A$1:$A$" + textlist.length);
|
|
|
+ DataValidationHelper helper = sheet.getDataValidationHelper();
|
|
|
+
|
|
|
+ DataValidationConstraint constraint = helper.createFormulaListConstraint(hideSheetName + "_data");
|
|
|
+
|
|
|
+ CellRangeAddressList regions = new CellRangeAddressList(firstRow, endRow, firstCol, endCol);
|
|
|
+
|
|
|
+ DataValidation dataValidation = helper.createValidation(constraint, regions);
|
|
|
+ if (StringUtils.isNotEmpty(promptContent))
|
|
|
+ {
|
|
|
+
|
|
|
+ dataValidation.createPromptBox("", promptContent);
|
|
|
+ dataValidation.setShowPromptBox(true);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (dataValidation instanceof XSSFDataValidation)
|
|
|
+ {
|
|
|
+ dataValidation.setSuppressDropDownArrow(true);
|
|
|
+ dataValidation.setShowErrorBox(true);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ dataValidation.setSuppressDropDownArrow(false);
|
|
|
+ }
|
|
|
+
|
|
|
+ sheet.addValidationData(dataValidation);
|
|
|
+
|
|
|
+ wb.setSheetHidden(wb.getSheetIndex(hideSheet), true);
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
* 解析导出值 0=男,1=女,2=未知
|
|
|
*
|