jxl使用

		WritableSheet ws = null;
		WritableWorkbook wwb = null;
		File DEResultFile = null;
		Workbook rwb = null;
		DEResultFile = new File(DEMatchResultFilePath + "数据字典比对匹配结果"+ SYSCURRENTDATASTR + ".xls");
		int rsRows = 0;
		int rsClos = 0;
		int count = 0;
		try {
			rwb = Workbook.getWorkbook(DEFile);// 直接读表复制
			wwb = Workbook.createWorkbook(DEResultFile, rwb);// 真实操作的xls
			ws = wwb.getSheet(0);
			rsRows = ws.getRows();//行数
			rsClos = ws.getColumns();//列数
			count = rsRows;
			System.out.println("rsRows" + rsRows);
		} catch (Exception e) {
			e.printStackTrace();
		}
		try{
			for(int i=0;i<4;i++){
				Label temp_label = new Label(titlenum[i], 0, title[i],getTitle());
				ws.addCell(temp_label);
			}
			System.out.println(rsClos);
			Label label = new Label(rsClos, 0, "比对结果",getTitle());
			ws.addCell(label);
			ws.setColumnView(rsClos, 40);
			for (int i = 1; i < DDCResultList.size(); i++) {
				
				System.out.println(DDCResultList.get(i).getCompaireResult());
				if(!DDCResultList.get(i).getCompaireResult().equals("待比对数据字典中不包含标准数据字典中此代码")){
					System.out.println(rsClos);
					Label temp_label = new Label(rsClos, DDCResultList.get(i).getRow(), DDCResultList.get(i).getCompaireResult());
					ws.addCell(temp_label);
				}
				else{ 
					//设置字体,加粗,颜色等
			        WritableFont font1 = new WritableFont(WritableFont.createFont("宋体"),11,WritableFont.NO_BOLD,false,UnderlineStyle.NO_UNDERLINE,Colour.RED);  
			  
			        WritableCellFormat cellFormat1 = new WritableCellFormat(font1);  
					Label temp_label = new Label (titlenum[0],count,DDCResultList.get(i).getDataDictTableName(),cellFormat1);
					ws.addCell(temp_label);
					temp_label = new Label (titlenum[1],count,"",cellFormat1);
					ws.addCell(temp_label);
					temp_label = new Label (titlenum[2],count,DDCResultList.get(i).getDataDictvalue(),cellFormat1);
					ws.addCell(temp_label);
					temp_label = new Label (titlenum[3],count,DDCResultList.get(i).getDataDictType(),cellFormat1);
					ws.addCell(temp_label);
					temp_label = new Label (rsClos,count,DDCResultList.get(i).getCompaireResult(),cellFormat1);
					ws.addCell(temp_label);
					count++;
				}
				
			}
			wwb.write();
			wwb.close();
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			if(rwb != null){
				rwb.close();
			}
		}


猜你喜欢

转载自blog.csdn.net/bbsdsz/article/details/68486134
jxl