本文整理了Java中org.apache.poi.hssf.usermodel.HSSFSheet.addValidationData()
方法的一些代码示例,展示了HSSFSheet.addValidationData()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HSSFSheet.addValidationData()
方法的具体详情如下:
包路径:org.apache.poi.hssf.usermodel.HSSFSheet
类名称:HSSFSheet
方法名:addValidationData
[英]Creates a data validation object
[中]创建数据验证对象
代码示例来源:origin: stackoverflow.com
HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet realSheet = workbook.createSheet("Sheet xls");
HSSFSheet hidden = workbook.createSheet("hidden");
for (int i = 0, length= countryName.length; i < length; i++) {
String name = countryName[i];
HSSFRow row = hidden.createRow(i);
HSSFCell cell = row.createCell(0);
cell.setCellValue(name);
}
Name namedCell = workbook.createName();
namedCell.setNameName("hidden");
namedCell.setRefersToFormula("hidden!$A$1:$A$" + countryName.length);
DVConstraint constraint = DVConstraint.createFormulaListConstraint("hidden");
CellRangeAddressList addressList = new CellRangeAddressList(0, 0, 0, 0);
HSSFDataValidation validation = new HSSFDataValidation(addressList, constraint);
workbook.setSheetHidden(1, true);
realSheet.addValidationData(validation);
FileOutputStream stream = new FileOutputStream("c:\\range.xls");
workbook.write(stream);
stream.close();
代码示例来源:origin: com.dexcoder/dexcoder-commons
/**
* 创建下拉列表列
*
* @param sheet sheet对象
* @param cell cell对象
* @param firstRowIndex 开始行索引
* @param lastRowIndex 结束行索引
* @param firstCellIndex 开始列索引
* @param lastCellIndex 结束列索引
* @param cellValue 列的值
*/
public void createSelectCellStyle(HSSFSheet sheet, HSSFCell cell, int firstRowIndex, int lastRowIndex,
int firstCellIndex, int lastCellIndex, String[] cellValue) {
CellRangeAddressList regions = new CellRangeAddressList(firstRowIndex, lastRowIndex, firstCellIndex,
lastCellIndex);
DVConstraint constraint = DVConstraint.createExplicitListConstraint(cellValue);
HSSFDataValidation dataValidate = new HSSFDataValidation(regions, constraint);
// 加入数据有效性到当前sheet对象
sheet.addValidationData(dataValidate);
// 设置默认显示的值
cell.setCellValue(cellValue[0]);
}
代码示例来源:origin: selfly/dexcoder-assistant
/**
* 创建下拉列表列
*
* @param sheet sheet对象
* @param cell cell对象
* @param firstRowIndex 开始行索引
* @param lastRowIndex 结束行索引
* @param firstCellIndex 开始列索引
* @param lastCellIndex 结束列索引
* @param cellValue 列的值
*/
public void createSelectCellStyle(HSSFSheet sheet, HSSFCell cell, int firstRowIndex, int lastRowIndex,
int firstCellIndex, int lastCellIndex, String[] cellValue) {
CellRangeAddressList regions = new CellRangeAddressList(firstRowIndex, lastRowIndex, firstCellIndex,
lastCellIndex);
DVConstraint constraint = DVConstraint.createExplicitListConstraint(cellValue);
HSSFDataValidation dataValidate = new HSSFDataValidation(regions, constraint);
// 加入数据有效性到当前sheet对象
sheet.addValidationData(dataValidate);
// 设置默认显示的值
cell.setCellValue(cellValue[0]);
}
内容来源于网络,如有侵权,请联系作者删除!