文件名称:
poi-3.6-20091214.jar
开发工具:
文件大小: 1mb
下载次数: 0
上传时间: 2012-02-07
详细说明: package exceltest; import java.io.FileOutputStream; import java.io.IOException; 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 ExcelUtile { public static void main(String[] args) throws IOException { HSSFWorkbook wb = new HSSFWorkbook();// excel文件对象 HSSFSheet sheetlist = wb.createSheet("sheetlist1");// 工作表对象1 HSSFSheet sheetlist2 = wb.createSheet("sheetlist2");// 工作表对象2 HSSFSheet sheetlist3 = wb.createSheet("sheetlist3");// 工作表对象3 FileOutputStream out = new FileOutputStream("c:/success6.xls"); //新建单元格 HSSFRow row = sheetlist.createRow(0); for(short i=0;i<10;i++){ //HSSFCell cell = row.getCell(i); HSSFCell cell = row.createCell(i); cell.setCellValue("列值" + i); //获取单元格内容。 //System.out.println( cell.getStringCellValue()); } //修改单元格 HSSFRow row2 = sheetlist.getRow(0); HSSFCell cell = row.getCell(2); cell.setCellValue("下拉选择"); HSSFCell cell2 = row.getCell(3); cell2.setCellValue("长度限制在1-5"); //有效性选择所需数据。 String[] textList = {"空闲", "已用"}; //数据有效性验证,下拉选择。 DVConstraint constraint = DVConstraint.createExplicitListConstraint(textList); CellRangeAddressList regions = new CellRangeAddressList((short) 1, (short) 20, (short) 2, (short) 2); HSSFDataValidation data_validation = new HSSFDataValidation(regions, constraint); sheetlist.addValidationData(data_validation); //有效性单元格长度控制。 DVConstraint constraint2 = DVConstraint.createNumericConstraint(DVConstraint.ValidationType.TEXT_LENGTH,DVConstraint.OperatorType.BETWEEN, "1", "5"); CellRangeAddressList regions2 = new CellRangeAddressList((short) 1, (short) 20, (short) 3, (short) 3); HSSFDataValidation data_validation2 = new HSSFDataValidation(regions2, constraint2); sheetlist.addValidationData(data_validation2); wb.write(out); out.close(); } } ...展开收缩
(系统自动生成,下载前可以参看下载内容)
下载文件列表
相关说明
- 本站资源为会员上传分享交流与学习,如有侵犯您的权益,请联系我们删除.
- 本站是交换下载平台,提供交流渠道,下载内容来自于网络,除下载问题外,其它问题请自行百度。
- 本站已设置防盗链,请勿用迅雷、QQ旋风等多线程下载软件下载资源,下载后用WinRAR最新版进行解压.
- 如果您发现内容无法下载,请稍后再次尝试;或者到消费记录里找到下载记录反馈给我们.
- 下载后发现下载的内容跟说明不相乎,请到消费记录里找到下载记录反馈给我们,经确认后退回积分.
- 如下载前有疑问,可以通过点击"提供者"的名字,查看对方的联系方式,联系对方咨询.