sezayir

This user hasn't shared any biographical information

Homepage: https://sezayir.wordpress.com

Workbook workbook = new XSSFWorkbook();

public static void createDropDown(String[] status, String defaultValue, Row row, int rowid, int cellid) {

Cell cell = row.createCell(cellid);
Sheet sheet = row.getSheet();
XSSFDataValidationHelper dvHelper = new XSSFDataValidationHelper((XSSFSheet) sheet);
XSSFDataValidationConstraint dvConstraint = (XSSFDataValidationConstraint) dvHelper.createExplicitListConstraint(status);
CellRangeAddressList addressList = new CellRangeAddressList(rowid, rowid, cellid, cellid);
XSSFDataValidation validation= (XSSFDataValidation) dvHelper.createValidation(dvConstraint, addressList);
validation.createErrorBox(ERROR_MESSSAGE, INVALID_DATA);
validation.setShowErrorBox(true);
sheet.addValidationData(validation);
sheet.getRow(rowid).getCell(cellid).setCellValue(defaultValue);
}

Advertisements

,

Leave a comment

GENERIC DROP DOWN WITH SXSSFWorkbook

 

Workbook workbook = new SXSSFWorkbook(200);

 

public static void createDropDown(String[] status, String defaultValue, Row row, int rowid, int cellid) {

Cell cell = row.createCell(cellid);
Sheet sheet = row.getSheet();
DataValidationHelper dvHelper = sheet.getDataValidationHelper();
XSSFDataValidationConstraint dvConstraint = (XSSFDataValidationConstraint) dvHelper.createExplicitListConstraint(status);
CellRangeAddressList addressList = new CellRangeAddressList(rowid, rowid, cellid, cellid);
XSSFDataValidation validation= (XSSFDataValidation) dvHelper.createValidation(dvConstraint, addressList);
validation.createErrorBox(ERROR_MESSSAGE, INVALID_DATA);
validation.setShowErrorBox(true);
sheet.addValidationData(validation);
sheet.getRow(rowid).getCell(cellid).setCellValue(defaultValue);
}

, ,

Leave a comment

apache poi dropDown List

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.util.CellRangeAddressList;
import org.apache.poi.xssf.usermodel.XSSFDataValidation;
import org.apache.poi.xssf.usermodel.XSSFDataValidationConstraint;
import org.apache.poi.xssf.usermodel.XSSFDataValidationHelper;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

 

public class XLCellDropDown {
public static void main(String args[]) throws FileNotFoundException {

 

XSSFWorkbook workbook = new XSSFWorkbook();
XSSFSheet sheet = workbook.createSheet(“Data Validation”);
Row row=sheet.createRow(0);
Cell cell=row.createCell(0);

XSSFDataValidationHelper dvHelper = new XSSFDataValidationHelper((XSSFSheet) row.getSheet());
XSSFDataValidationConstraint dvConstraint = (XSSFDataValidationConstraint) dvHelper.createExplicitListConstraint(new String[]{“java”, “Spring”, “Angular2”});

CellRangeAddressList addressList = new CellRangeAddressList(0, 0, 0, 0);

XSSFDataValidation validation = (XSSFDataValidation)dvHelper.createValidation(
dvConstraint, addressList);
validation.setShowErrorBox(true);
validation. createErrorBox(“ERROR MEESAGE:Invalid Data”, “Please provide valid data in the dropdown list.”);

sheet.addValidationData(validation);

sheet.getRow(0).getCell(0).setCellValue(“spring”);

FileOutputStream fileOut = new FileOutputStream(“D:\\report\\XLCellDropDown.xlsx”);
try {
workbook.write(fileOut);
fileOut.close();
workbook.close();

System.out.println(“Test”);
}
catch (IOException e) {
e.printStackTrace();
}
}
}

, ,

Leave a comment