//将数据写入Excel文档
public static String writeExcel(List<Compare4> data_list,String path,String file_name) throws IOException, RowsExceededException, WriteException{
WritableWorkbook workBook_xs = null;
WritableSheet sheet_xs = null;
File file_xs = null;
Label label = null;
String sep = System.getProperty("file.separator"); // 分隔符
String filePath = path + sep + file_name+".xls";
file_xs = new File(filePath);
file_xs.createNewFile(); // 创建新文件
workBook_xs = Workbook.createWorkbook(file_xs);
sheet_xs = workBook_xs.createSheet("sheet1", 0);
sheet_xs.setColumnView(0, 15);
sheet_xs.setColumnView(1, 20);
sheet_xs.setColumnView(2, 15);
sheet_xs.setColumnView(3, 15);
sheet_xs.setColumnView(4, 20);
sheet_xs.setColumnView(5, 20);
sheet_xs.setColumnView(6, 20);
sheet_xs.setColumnView(7, 20);
sheet_xs.setColumnView(9, 20);
sheet_xs.setColumnView(10, 20);
sheet_xs.setColumnView(11, 20);
sheet_xs.setColumnView(12, 20);
sheet_xs.setColumnView(13, 20);
sheet_xs.setColumnView(14, 20);
sheet_xs.setColumnView(15, 20);
sheet_xs.setColumnView(16, 20);
sheet_xs.setColumnView(17, 20);
sheet_xs.setColumnView(18, 20);
sheet_xs.setColumnView(19, 20);
sheet_xs.setColumnView(20, 20);
sheet_xs.setColumnView(21, 20);
sheet_xs.setColumnView(22, 20);
sheet_xs.setColumnView(23, 20);
sheet_xs.setColumnView(24, 20);
sheet_xs.setColumnView(25, 20);
sheet_xs.setColumnView(26, 20);
sheet_xs.setColumnView(27, 20);
sheet_xs.setColumnView(28, 20);
sheet_xs.setColumnView(29, 20);
sheet_xs.setColumnView(30, 30);
sheet_xs.setColumnView(31, 20);
sheet_xs.setColumnView(32, 20);
sheet_xs.setColumnView(33, 20);
sheet_xs.setColumnView(34, 20);
sheet_xs.setColumnView(35, 20);
sheet_xs.setColumnView(36, 20);
sheet_xs.setColumnView(37, 20);
sheet_xs.setColumnView(38, 20);
sheet_xs.setColumnView(39, 20);
sheet_xs.setColumnView(40, 20);
sheet_xs.setColumnView(41, 20);
sheet_xs.setColumnView(42, 20);
sheet_xs.setColumnView(43, 20);
sheet_xs.setColumnView(34, 20);
sheet_xs.setColumnView(35, 20);
sheet_xs.setColumnView(46, 20);
sheet_xs.setColumnView(47, 20);
sheet_xs.setColumnView(48, 20);
sheet_xs.setColumnView(49, 20);
//设置字体
WritableFont font = new WritableFont(WritableFont.TIMES, 10, WritableFont.BOLD, true);
WritableCellFormat format = new WritableCellFormat(font);
//设置表头开始----------------------------------
label = new Label(0, 0, "序号",format);
sheet_xs.addCell(label);
label = new Label(1, 0, "采集表号",format);
sheet_xs.addCell(label);
label = new Label(2, 0, "采集批次",format);
sheet_xs.addCell(label);
label = new Label(3, 0, "个人编号",format);
sheet_xs.addCell(label);
label = new Label(4, 0, "采集状态",format);
sheet_xs.addCell(label);
label = new Label(5, 0, "社保身份证",format);
sheet_xs.addCell(label);
label = new Label(6, 0, "社保姓名",format);
sheet_xs.addCell(label);
label = new Label(7, 0, "社保性别",format);
sheet_xs.addCell(label);
label = new Label(8, 0, "社保民族",format);
sheet_xs.addCell(label);
label = new Label(9, 0, "社保出生日期",format);
sheet_xs.addCell(label);
label = new Label(10, 0, "社保户口地址",format);
sheet_xs.addCell(label);
label = new Label(11, 0, "社保号",format);
sheet_xs.addCell(label);
label = new Label(12, 0, "单位编号",format);
sheet_xs.addCell(label);
label = new Label(13, 0, "单位名称",format);
sheet_xs.addCell(label);
label = new Label(14, 0, "社保导入人员",format);
sheet_xs.addCell(label);
label = new Label(15, 0, "社保导入日期",format);
sheet_xs.addCell(label);
label = new Label(16, 0, "采集身份证",format);
sheet_xs.addCell(label);
label = new Label(17, 0, "采集姓名",format);
sheet_xs.addCell(label);
label = new Label(18, 0, "采集性别",format);
sheet_xs.addCell(label);
label = new Label(19, 0, "采集民族",format);
sheet_xs.addCell(label);
label = new Label(20, 0, "采集出生日期",format);
sheet_xs.addCell(label);
label = new Label(21, 0, "采集户口地址",format);
sheet_xs.addCell(label);
label = new Label(22, 0, "证件类型",format);
sheet_xs.addCell(label);
label = new Label(23, 0, "证件有效期",format);
sheet_xs.addCell(label);
label = new Label(24, 0, "国籍",format);
sheet_xs.addCell(label);
label = new Label(25, 0, "人员类型",format);
sheet_xs.addCell(label);
label = new Label(26, 0, "人员状态",format);
sheet_xs.addCell(label);
label = new Label(27, 0, "户口性质",format);
sheet_xs.addCell(label);
label = new Label(28, 0, "通讯地址",format);
sheet_xs.addCell(label);
label = new Label(29, 0, "邮政编码",format);
sheet_xs.addCell(label);
label = new Label(30, 0, "联系电话",format);
sheet_xs.addCell(label);
label = new Label(31, 0, "电子邮箱",format);
sheet_xs.addCell(label);
label = new Label(32, 0, "所在社区",format);
sheet_xs.addCell(label);
label = new Label(33, 0, "监护人姓名",format);
sheet_xs.addCell(label);
label = new Label(34, 0, "监护人身份证",format);
sheet_xs.addCell(label);
label = new Label(35, 0, "监护人联系电话",format);
sheet_xs.addCell(label);
label = new Label(36, 0, "监护人关系",format);
sheet_xs.addCell(label);
label = new Label(37, 0, "代理人姓名",format);
sheet_xs.addCell(label);
label = new Label(38, 0, "代理人身份证",format);
sheet_xs.addCell(label);
label = new Label(39, 0, "代理人联系电话",format);
sheet_xs.addCell(label);
label = new Label(40, 0, "代理人关系",format);
sheet_xs.addCell(label);
label = new Label(41, 0, "个人照片",format);
sheet_xs.addCell(label);
label = new Label(42, 0, "指纹所属手指编码",format);
sheet_xs.addCell(label);
label = new Label(43, 0, "指纹1",format);
sheet_xs.addCell(label);
label = new Label(44, 0, "指纹2",format);
sheet_xs.addCell(label);
label = new Label(45, 0, "指纹3",format);
sheet_xs.addCell(label);
label = new Label(46, 0, "指纹4",format);
sheet_xs.addCell(label);
label = new Label(47, 0, "采集比对结果",format);
sheet_xs.addCell(label);
label = new Label(48, 0, "采集人员",format);
sheet_xs.addCell(label);
label = new Label(49, 0, "采集日期",format);
sheet_xs.addCell(label);
//设置表头结束----------------------------------
int count =0;
//循环写数据开始
for (int k = 0; k < data_list.size(); k++) {
Compare4 compaer4 = (Compare4)data_list.get(k);
label = new Label(0, k+1, (k+1)+"");//序列号
sheet_xs.addCell(label);
label = new Label(1, k+1, compaer4.getCJBH());
sheet_xs.addCell(label);
label = new Label(2, k+1, compaer4.getCJPC());
sheet_xs.addCell(label);
label = new Label(3, k+1, compaer4.getSBID());
sheet_xs.addCell(label);
label = new Label(4, k+1, compaer4.getCJZT());
sheet_xs.addCell(label);
label = new Label(5, k+1, compaer4.getSBSFZ());
sheet_xs.addCell(label);
label = new Label(6, k+1, compaer4.getSBXM());
sheet_xs.addCell(label);
label = new Label(7, k+1, compaer4.getSBXB());
sheet_xs.addCell(label);
label = new Label(8, k+1, compaer4.getSBMZ());
sheet_xs.addCell(label);
label = new Label(9, k+1, compaer4.getSBCSRQ());
sheet_xs.addCell(label);
label = new Label(10, k+1, compaer4.getSBHKDZ());
sheet_xs.addCell(label);
label = new Label(11, k+1, compaer4.getSBBH());
sheet_xs.addCell(label);
label = new Label(12, k+1, compaer4.getDWBH());
sheet_xs.addCell(label);
label = new Label(13, k+1, compaer4.getDWMC());
sheet_xs.addCell(label);
label = new Label(14, k+1, compaer4.getSBDRRY());
sheet_xs.addCell(label);
label = new Label(15, k+1, compaer4.getSBDRRQ());
sheet_xs.addCell(label);
label = new Label(16, k+1, compaer4.getCJSFZ());
sheet_xs.addCell(label);
label = new Label(17, k+1, compaer4.getCJXM());
sheet_xs.addCell(label);
label = new Label(18, k+1, compaer4.getCJXB());
sheet_xs.addCell(label);
label = new Label(19, k+1, compaer4.getCJMZ());
sheet_xs.addCell(label);
label = new Label(20, k+1, compaer4.getCJCSRQ());
sheet_xs.addCell(label);
label = new Label(21, k+1, compaer4.getCJHKDZ());
sheet_xs.addCell(label);
label = new Label(22, k+1, compaer4.getZJLX());
sheet_xs.addCell(label);
label = new Label(23, k+1, compaer4.getZJYXQ());
sheet_xs.addCell(label);
label = new Label(24, k+1, compaer4.getGJ());
sheet_xs.addCell(label);
label = new Label(25, k+1, compaer4.getCARDTYPE());
sheet_xs.addCell(label);
label = new Label(26, k+1, compaer4.getRYZT());
sheet_xs.addCell(label);
label = new Label(27, k+1, compaer4.getHKXZ());
sheet_xs.addCell(label);
label = new Label(28, k+1, compaer4.getTXDZ());
sheet_xs.addCell(label);
label = new Label(29, k+1, compaer4.getYZBM());
sheet_xs.addCell(label);
label = new Label(30, k+1, compaer4.getLXDH());
sheet_xs.addCell(label);
label = new Label(31, k+1, compaer4.getEMAIL());
sheet_xs.addCell(label);
label = new Label(32, k+1, compaer4.getSZSQ());
sheet_xs.addCell(label);
label = new Label(33, k+1, compaer4.getJHRXM());
sheet_xs.addCell(label);
label = new Label(34, k+1, compaer4.getJHRZH());
sheet_xs.addCell(label);
label = new Label(35, k+1, compaer4.getJHRDH());
sheet_xs.addCell(label);
label = new Label(36, k+1, compaer4.getJHRGX());
sheet_xs.addCell(label);
label = new Label(37, k+1, compaer4.getDLRXM());
sheet_xs.addCell(label);
label = new Label(38, k+1, compaer4.getDLRZH());
sheet_xs.addCell(label);
label = new Label(39, k+1, compaer4.getDLRDH());
sheet_xs.addCell(label);
label = new Label(40, k+1, compaer4.getDLRGX());
sheet_xs.addCell(label);
label = new Label(41, k+1, "");//个人照片
sheet_xs.addCell(label);
label = new Label(42, k+1, compaer4.getFINGERDEFI());
sheet_xs.addCell(label);
label = new Label(43, k+1, "");//指纹1
sheet_xs.addCell(label);
label = new Label(44, k+1, "");//指纹2
sheet_xs.addCell(label);
label = new Label(45, k+1, "");//指纹3
sheet_xs.addCell(label);
label = new Label(46, k+1, "");//指纹4
sheet_xs.addCell(label);
label = new Label(47, k+1, compaer4.getCJBDJG());
sheet_xs.addCell(label);
label = new Label(48, k+1, compaer4.getCJRY());
sheet_xs.addCell(label);
label = new Label(49, k+1, compaer4.getCJRQ());
sheet_xs.addCell(label);
WritableFont wf = new WritableFont(WritableFont.ARIAL);
WritableCellFormat wcf = new WritableCellFormat(wf);
label.setCellFormat(wcf);
count++;
}
//循环写数据结束
workBook_xs.write();
workBook_xs.close();
return String.valueOf(count);
}
java 读取excel 2003版
最新推荐文章于 2021-02-26 02:48:35 发布