Struts2 excel 생성 및 poi 다운로드 방법

3753 단어 Excel
strtus2 excel 생성 및 다운로드 (poi 방식)
 
흐름에서 직접 생성하여 로컬로 다운로드할 수 있습니다.
                    if (sList != null) {
            
                                int rows = 1;
		HSSFWorkbook wk = new HSSFWorkbook();
		HSSFSheet sheet = wk.createSheet(" ");
		/* Excel 、 */			
		sheet.setDefaultColumnWidth((short)15);
		/*       */
		HSSFFont font = wk.createFont();
		font.setFontHeightInPoints((short)14);	// 
		font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);//  
		font.setColor(HSSFColor.RED.index);		// 
		/*  font  */
		CellStyle style = wk.createCellStyle();
		style.setFont(font);
		//
		HSSFFont font1 = wk.createFont();
		font1.setFontHeightInPoints((short)12);	// 
		font1.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);//  
		font1.setColor(HSSFColor.BLACK.index);		// 
		/*  font  */
		CellStyle style1 = wk.createCellStyle();
		style1.setFont(font1);
		HSSFRow row = sheet.createRow(rows++);
		HSSFRow row0 = sheet.createRow(0);
		/*   */
		sheet.addMergedRegion(new CellRangeAddress(0, 0,  0,  4));
		HSSFCell cell0 = row0.createCell(0, HSSFCell.CELL_TYPE_STRING);
		cell0.setCellStyle(style);
		cell0.setCellValue(title);
		int column = 0;
			
		//"   ", " ", "   ", "   ", "   
		HSSFCell cell = row.createCell(column++, HSSFCell.CELL_TYPE_STRING);
		cell.setCellValue("   ");
		cell.setCellStyle(style1);
		cell = row.createCell(column++, HSSFCell.CELL_TYPE_STRING);
		cell.setCellValue(" ");
		cell.setCellStyle(style1);
		cell = row.createCell(column++, HSSFCell.CELL_TYPE_STRING);
		cell.setCellValue("   ");
		cell.setCellStyle(style1);
		cell = row.createCell(column++, HSSFCell.CELL_TYPE_STRING);
		cell.setCellValue("   ");
		cell.setCellStyle(style1);
		cell = row.createCell(column++, HSSFCell.CELL_TYPE_STRING);
		cell.setCellValue("   ");
		cell.setCellStyle(style1);
		cell = row.createCell(column++, HSSFCell.CELL_TYPE_STRING);
		cell.setCellValue("   ");
		cell.setCellStyle(style1);
					for (SdProduct sdp : sList) {
				row = sheet.createRow(rows++);
				column = 0;
				cell = row.createCell(column++, HSSFCell.CELL_TYPE_NUMERIC);
				cell.setCellValue(sdp.getSdTitle().replaceAll("<[^>]*>",""));
				cell = row.createCell(column++, HSSFCell.CELL_TYPE_STRING);
				cell.setCellValue(sdp.getSdConName());
				cell = row.createCell(column++, HSSFCell.CELL_TYPE_STRING);
				cell.setCellValue(sdp.getSdTel());
				cell = row.createCell(column++, HSSFCell.CELL_TYPE_STRING);
				cell.setCellValue(sdp.getSdMobile());
				cell = row.createCell(column++, HSSFCell.CELL_TYPE_STRING);
				cell.setCellValue(sdp.getSdUpdate());
				cell = row.createCell(column++, HSSFCell.CELL_TYPE_STRING);
				cell.setCellValue(sdp.getSdComment().replaceAll("<[^>]*>","").replaceAll("&nbsp;", ""));
			}
		} else {
			System.out.println(" ");
		}
		try {
			ByteArrayOutputStream out = new ByteArrayOutputStream();
			wk.write(out);
			requests.setAttribute("excelStream", new ByteArrayInputStream(
					out.toByteArray()));
			requests.setAttribute("filename", fileName);//  
			return SUCCESS;
		} catch (Throwable th) {
			th.printStackTrace();
			System.out.println(" Excel ");
			return ERROR;
		}

 

좋은 웹페이지 즐겨찾기