OutputStream os = new FileOutputStream(file);//新建一个File文件,放入流中
WritableWorkbook workbook = Workbook.createWorkbook(os);//创建一个工作簿
WritableSheet sheet = workbook.createSheet("Sheet1", 0);//创建第一个工作表,并命名
// 表头样式
WritableFont bold1 = new WritableFont(WritableFont.createFont("微软雅黑"), 14,WritableFont.BOLD);//设置字体,自号,加粗
bold1.setColour(Colour.RED);//设置字体颜色为红色
WritableCellFormat title1Formate = new WritableCellFormat(bold1);// 生成一个单元格样式控制对象
title1Formate.setAlignment(jxl.format.Alignment.CENTRE);// 单元格中的内容水平方向居中
title1Formate.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE);// 单元格的内容垂直方向居中
title1Formate.setBorder(jxl.format.Border.ALL,jxl.format.BorderLineStyle.THIN);//单元格边框设置
title1Formate.setBackground(Colour.GRAY_25);//设置背景颜色为绿色
//日期样式
DateFormat df=new DateFormat("yyyy-MM-dd");
WritableFont bold5 = new WritableFont(WritableFont.createFont("宋体"), 11);
WritableCellFormat dateFormate = new WritableCellFormat(bold5,df);// 生成一个单元格样式控制对象
dateFormate.setAlignment(jxl.format.Alignment.LEFT);// 单元格中的内容水平方居中
sheet.mergeCells(0, 0, 10, 0);//合并单元格
Label title = new Label(0, 0, "xxxxxxx", titleFormate);
sheet.setRowView(0, 480, false);// 设置行高,单位问题还没有解决
sheet.setColumnView(0, 15);//设置列宽
WritableCellFeatures titlexFeatures=new WritableCellFeatures();
titlexFeatures.setComment("说明:\r如果没有代理证\r可以身份证号代替提供公函");
title.setCellFeatures(titlexFeatures);//设置标注内容
List<String> gList = new ArrayList<String>(); //设置下拉框的内容
gList.add("M-男");
gList.add("F-女");
gList.add("U-不详");
WritableCellFeatures wcf=new WritableCellFeatures();
wcf.setDataValidationList(gList);
title.setCellFeatures(wcf);//添加下拉框,即数据有效性
sheet.addCell(title);
DateTime brokerEmploy=new DateTime(i++,j,new Date(),dateFormate);//插入日期数据,格式在开头有设定
sheet.addCell(brokerEmploy);//还有数字格式,这里就不写了,换成number就可以了
workbook.write();
workbook.close();
os.close();//关闭流