poiデータ有効性ドロップダウンリスト

1720 ワード

関数の定義
    public HSSFDataValidation SetDataValidation(String[] textList, int firstRow, int endRow, int firstCol, int endCol) {  
        //            
        log.info("   :" + firstRow + "___   :" + firstCol + "___   :" + endRow + "___   :" + endCol);  
        //           
        DVConstraint constraint = DVConstraint.createExplicitListConstraint(textList);  
        // DVConstraint constraint = new DVConstraint();  
        constraint.setExplicitListValues(textList);  
      
        //                 。  
        //        :   、   、   、     
        CellRangeAddressList regions = new CellRangeAddressList((short) firstRow, (short) endRow, (short) firstCol, (short) endCol);  
      
        //          
        HSSFDataValidation data_validation = new HSSFDataValidation(regions, constraint);  
      
        return data_validation;  
    }  

呼び出しクラス
    import java.io.FileOutputStream;  
    import java.io.IOException;  
      
    import org.apache.poi.hssf.usermodel.HSSFSheet;  
    import org.apache.poi.hssf.usermodel.HSSFWorkbook;  
      
    public class Test {  
        public static void main(String[] args) throws IOException {  
            HSSFWorkbook wb = new HSSFWorkbook();// excel      
            HSSFSheet sheetlist = wb.createSheet("sheetlist");//        
            FileOutputStream out = new FileOutputStream("success.xls");  
            String[] textList = { "  1", "  2" };  
            sheetlist.addValidationData((new OracleToExcel()).SetDataValidation(textList, 1,2, 3, 4));  
            wb.write(out);  
            out.close();  
        }  
    }