poi 생성 excel 공통 방법

설명: 이 방법은 도움말 클래스 PoiExcelUtil에 의존합니다.java.
/**
	 *  excel
	 * @param dateList String 
	 * @param titleArray  
	 * @param sheetName	 sheet 
	 * @param fileName  ( paht+fileName+sysdate+.xls  :d:/ 2013-10-10.xls)
	 * @param path  
	 */
	public static boolean createExcel(List<String[]> dateList,String[] titleArray,String sheetName,String fileName,String path,String orderDate){
		try {
			if (null!=dateList && dateList.size()>0){
				HSSFWorkbook wb = new HSSFWorkbook();
				HSSFSheet sheet = PoiExcelUtil.createSheet(wb, sheetName);
				Font font = PoiExcelUtil.createFont(wb, HSSFFont.BOLDWEIGHT_NORMAL, HSSFFont.COLOR_NORMAL, (short)10);//2: ,3: ,4: 
				CellStyle cellStyle = PoiExcelUtil.createBorderCellStyle(wb, HSSFColor.BLACK.index, HSSFColor.WHITE.index, HSSFCellStyle.ALIGN_CENTER, font);
				HSSFRow row = PoiExcelUtil.createRow(sheet, 0, 250);// 
				HSSFCell cell = null;
				Font titleFont = PoiExcelUtil.createFont(wb, HSSFFont.BOLDWEIGHT_BOLD, HSSFFont.COLOR_NORMAL, (short)10);//2: ,3: ,4: 
				CellStyle titleCellStyle = PoiExcelUtil.createBorderCellStyle(wb, HSSFColor.BLACK.index, HSSFColor.WHITE.index, HSSFCellStyle.ALIGN_CENTER, titleFont);
				for (int j=0;j<titleArray.length;j++){
					cell = PoiExcelUtil.createCell(row, j, titleCellStyle);
					cell.setCellValue(titleArray[j]);
					cell.setCellStyle(titleCellStyle);
				}
				for (int i=0;i<dateList.size();i++){
					row = PoiExcelUtil.createRow(sheet, i+1, 250);
					String [] dateArray = dateList.get(i);
					for (int j=0;j<dateArray.length;j++){
						cell = PoiExcelUtil.createCell(row, j, cellStyle);
						cell.setCellValue(dateArray[j]);
						cell.setCellStyle(cellStyle);
					}
				}
				String fileNameStr = path+"/"+orderDate+"/"+fileName+".xls";
				PoiExcelUtil.writeWorkbook(wb, fileNameStr);
				return true;
			}else{
				log.error(" , "+fileName+CommonUtil.dateConvert(new Date(), "yyyy-MM-dd")+".xls");
				return false;
			}
		} catch (Exception e) {
			log.error(" excel , :"+fileName+CommonUtil.dateConvert(new Date(), "yyyy-MM-dd")+".xls",e);
			return false;
		}
	}

좋은 웹페이지 즐겨찾기