POI 작업 Excel, 드롭다운 상자 만들기

1637 단어
/**
 * 
 */
package test.excel;

/**
 * @author seven
 *2013-4-11 09:15:23
 */

import java.io.FileOutputStream;

import java.util.Date;

import org.apache.poi.hssf.usermodel.DVConstraint;

import org.apache.poi.hssf.usermodel.HSSFCell;

import org.apache.poi.hssf.usermodel.HSSFDataValidation;

import org.apache.poi.hssf.usermodel.HSSFRow;

import org.apache.poi.hssf.usermodel.HSSFSheet;

import org.apache.poi.hssf.usermodel.HSSFWorkbook;

import org.apache.poi.hssf.util.CellRangeAddressList;

public class POI
{

	public static void main(String[] args)

	{

		String[] list = { " ", " ", "SAP", " " };

		new POI().createListBox(list);
		return;

	}

	public void createListBox(String[] list)

	{

		//  

		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(list);

		//  

		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");

	}
}

좋은 웹페이지 즐겨찾기