java 读取excel 2003版

	//将数据写入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);
	}

public static int createdExcel(String PATH, List list, String title, String[] rowsName, String merged) { try { File myFile = new File(PATH); if (!myFile.exists()) { myFile.createNewFile(); } WritableWorkbook wbook = Workbook.createWorkbook(myFile); // 创建一个可写返回工作薄同给定文件名 WritableSheet wsheet = wbook.createSheet(title, 0); // sheet名称 // 设置字体 WritableFont wfont = new WritableFont(WritableFont.createFont("宋体"), 10, WritableFont.BOLD); WritableCellFormat wcfFC = new WritableCellFormat(wfont); wcfFC.setBorder(jxl.format.Border.ALL, jxl.format.BorderLineStyle.THIN); //单元格边缘线格式设置 wcfFC.setAlignment(jxl.format.Alignment.CENTRE); // 居中对齐 wcfFC.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE); //垂直居中 //wcfFC.setBackground(jxl.format.Colour.BLUE); // 蓝色底 // 设置行高和列宽 //wsheet.setColumnView(列数, 列宽); //wsheet.setRowView(行数, 行高); // 开始生成主体内容 for (int i = 0 ; i < rowsName.length; i++) { wsheet.addCell(new Label(i, 0, rowsName[i], wcfFC)); wsheet.setColumnView(i, 12); } wfont = new WritableFont(WritableFont.createFont("宋体"), 10, WritableFont.NO_BOLD); wcfFC = new WritableCellFormat(wfont); wcfFC.setBorder(jxl.format.Border.ALL, jxl.format.BorderLineStyle.THIN); //单元格边缘线格式设置 //是数字时的格式化 // jxl.write.NumberFormat numberFormat = new jxl.write.NumberFormat(NumberFormat.CURRENCY_DOLLAR); // jxl.write.WritableCellFormat wcfFCNUMBER = new jxl.write.WritableCellFormat(wfont,numberFormat); // wcfFCNUMBER.setBorder(jxl.format.Border.ALL, jxl.format.BorderLineStyle.THIN); //单元格边缘线格式设置 // wcfFCNUMBER.setAlignment(jxl.format.Alignment.CENTRE); // 居中对齐 // wcfFCNUMBER.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE); //垂直居中 //是数字时的格式化 wcfFC.setWrap(true); //合并单元格操作 //wsheet.mergeCells(坐标列1, 坐标行1, 坐标列2, 坐标行2) for (int i = 0; i < list.size(); i++) { String[] args = (String[]) list.get(i); for (int j = 0; j < args.length; j ++) { if (args[j].length()<15 ) { wsheet.addCell(new jxl.write.Number(j, i+1, Float.parseFloat(args[j]), wcfFC)); } else { wsheet.addCell(new Label(j, i+1, args[j], wcfFC)); } } if (merged.indexOf("," + (i+1) + ",") >=0) { wsheet.mergeCells(0, i+1, args.length-1, i+1); wsheet.setRowView(i, 1000); } //打印分页符 if (i % 20 == 0) { //wsheet.addRowPageBreak(i); } } // 主体内容生成结束 wbook.write(); // 写入文件 wbook.close(); return 1; } catch (Exception ex) { ex.printStackTrace(); return 0; } }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值