excel 파일로 내용 내보내기 방법

1803 단어
자세히 보기
@SuppressWarnings("rawtypes")
	public InputStream exportExcel(String[] titles,List rtList){
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		WritableWorkbook workbook;
		try {
			workbook = Workbook.createWorkbook(baos);
			WritableSheet sheet = workbook.createSheet("Sheet1", 0);

			// 、 
			setHead(titles,sheet);
			
			// 、 
			if(rtList!=null && rtList.size()>0){
				// 
				WritableCellFormat wcf = new WritableCellFormat();
				wcf.setBorder(jxl.format.Border.ALL,jxl.format.BorderLineStyle.THIN,jxl.format.Colour.BLACK);
				
				int row = 1;
				Integer[] len = getLength(titles,rtList);
				for(int i = 0 ;i")
								 .replace("+", "+");
						if("null".equals(value)||"NULL".equals(value)){
							value="";
						}
						Label labelN = new Label(j, row,value.trim());
						labelN.setCellFormat(wcf);
						sheet.addCell(labelN); 
						sheet.setColumnView(j,len[j]);
						
						if (titles[j].indexOf(" ")>0) {
							sheet.setColumnView(j,0);// 0
						} else {
							sheet.setColumnView(j,len[j]);
						}
					}
					
					row++;
				}
			}
			workbook.write();
			workbook.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
		InputStream inputStream = new ByteArrayInputStream(baos.toByteArray());
		return inputStream;
	}

좋은 웹페이지 즐겨찾기