POI 생성 excel 리본 드롭다운

1629 단어 Excel
package com.test;

import java.io.FileOutputStream;

import org.apache.poi2.hssf.usermodel.DVConstraint;
import org.apache.poi2.hssf.usermodel.HSSFCell;
import org.apache.poi2.hssf.usermodel.HSSFDataValidation;
import org.apache.poi2.hssf.usermodel.HSSFRow;
import org.apache.poi2.hssf.usermodel.HSSFSheet;
import org.apache.poi2.hssf.usermodel.HSSFWorkbook;
import org.apache.poi2.hssf.util.CellRangeAddressList;

public class JExcel {

	public static void main(String[] args) {
		HSSFWorkbook wb = new HSSFWorkbook();
		HSSFSheet sheet = wb.createSheet("new sheet");
		//  , 
		HSSFRow row = sheet.createRow(0);
		HSSFCell cell = row.createCell(0);
		//  
		cell.setCellValue(" ");//  
		//  
		//  (0,0) 
		CellRangeAddressList regions = new CellRangeAddressList(0, 0, 0, 0);
		//  
		DVConstraint constraint = DVConstraint.createExplicitListConstraint(new String[] { "2", "3" });
		//  
		HSSFDataValidation data_validation = new HSSFDataValidation(regions,constraint);
		//  sheet 
		sheet.addValidationData(data_validation);
		//  
		FileOutputStream fileOut;
		try {
			fileOut = new FileOutputStream("workbook.xls");
			wb.write(fileOut);
			fileOut.close();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();

		}
		//  
		System.out.println("Over");

	}
}

좋은 웹페이지 즐겨찾기