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

1938 단어 Excel
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");
 }
}

다음에서 시작합니다.http://ttaale.iteye.com/blog/836306

좋은 웹페이지 즐겨찾기