poi建立下拉框

來源:互聯網
上載者:User
poi建立下拉框

package com.cloud.poi.utils;import java.io.FileOutputStream;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;import org.apache.poi.ss.SpreadsheetVersion;/** * poi建立下拉框 * @author Henry */public class PoiCheckBox97{public static void main(String[] args){String[] list = { "JAVA", "C", "易語言", "GO" };new PoiCheckBox97().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("請選擇");// 這是實驗// 產生下拉式清單// 對(row0,rowMax,col0,colMax)所有儲存格有效int maxRowNum = SpreadsheetVersion.EXCEL97.getLastRowIndex();//maxRowNum=65535System.out.println("maxRowNum:"+maxRowNum);int maxColNum = SpreadsheetVersion.EXCEL97.getLastColumnIndex();System.out.println("maxColNum:"+maxColNum);//maxColNum=255CellRangeAddressList regions = new CellRangeAddressList(0, maxRowNum, 0, maxColNum);// 產生下拉框內容DVConstraint constraint = DVConstraint.createExplicitListConstraint(list);// 綁定下拉框和作用地區HSSFDataValidation data_validation = new HSSFDataValidation(regions,constraint);// 對sheet頁生效sheet.addValidationData(data_validation);// 寫入檔案FileOutputStream fileOut;try {fileOut = new FileOutputStream("d:/workbook.xls");wb.write(fileOut);fileOut.close();} catch (Exception e) {e.printStackTrace();}// 結束System.out.println("Over");}}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.