excel 的相关操作:
表格中指定位置插入内容,其余内容依次下移:
sheet.shiftRows(rowNo, sheet.getLastRowNum(), 1,true,true);
sheet.createRow(rowNo);
row = sheet.getRow(rowNo);
for (int i = 0; i < sourceRow.getLastCellNum(); i++) {
Cell newCell = row.createCell(i);
}
合并单元格操作:
// 合并单元格
CellRangeAddress cellRangeAddress = new CellRangeAddress(rowNo,rowNo,4,6);
sheet.addMergedRegion(cellRangeAddress);
设置下拉框操作:
CellRangeAddressList addressList = new CellRangeAddressList(line-list.size(),line,col,col);
DataValidationHelper helper = sheet.getDataValidationHelper();
// 获取要设置的下拉框的内容
String[] dropDownBoxValue = DropDownBoxEnum.getValueByCode(dropDownBoxName);
DataValidationConstraint constraint = helper.createExplicitListConstraint(dropDownBoxValue);
DataValidation dataValidation = helper.createValidation(constraint, addressList);
// 处理excel兼容性问题
if(dataValidation instanceof XSSFDataValidation){
dataValidation.setSuppressDropDownArrow(Boolean.TRUE);
dataValidation.setShowErrorBox(Boolean.TRUE);
}else {
dataValidation.setSuppressDropDownArrow(Boolean.FALSE);
}
sheet.addValidationData(dataValidation);