poi를 이용하여 excel 코드 세션 내보내기

2956 단어 poiExcel
try {
            OutputStream os = response.getOutputStream();
            response.reset();//  
            response.setHeader("Content-disposition",
                "attachment; filename=" + new String("images".getBytes("GB2312"), "iso8859_1")
                        + ".xls");//  
            response.setContentType("application/msexcel");//  
            /**************  xls  *************/
            HSSFWorkbook workbook = new HSSFWorkbook(); //  
            HSSFCellStyle style = workbook.createCellStyle(); //  
            /**************   *************/
            style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); //  
            style.setAlignment(HSSFCellStyle.ALIGN_CENTER); //  
            style.setWrapText(true);
            HSSFSheet sheet = workbook.createSheet(); //  sheet
            //  
            //  
            HSSFRow row1 = sheet.createRow(0);
            //  
            HSSFCell cell1 = row1.createCell(0);//  
            HSSFCell cell2 = row1.createCell(1);
            HSSFCell cell3 = row1.createCell(2);
            HSSFCell cell4 = row1.createCell(3);
            //  
            cell1.setCellType(HSSFCell.CELL_TYPE_STRING);
            cell2.setCellType(HSSFCell.CELL_TYPE_STRING);
            cell3.setCellType(HSSFCell.CELL_TYPE_STRING);
            cell4.setCellType(HSSFCell.CELL_TYPE_STRING);

            cell1.setCellValue(" / ");
            cell2.setCellValue("  ( )");
            cell3.setCellValue(" ");
            cell4.setCellValue(" ");
            //  
            sheet.setColumnWidth(0, 8000);
            sheet.setColumnWidth(1, 10000);
            sheet.setColumnWidth(2, 5000);
            sheet.setColumnWidth(3, 6000);

            HSSFRow row = null;
            //  
            for (int r = 1; r <= filelist.size(); r++) //  
            {
                img = filelist.get(r - 1);
                row = sheet.createRow(r);
                row.createCell(0).setCellValue(
                    img.getUploadFileInfo().subStr(img.getUploadFileInfo().getThumbnailurl()) + " "
                            + img.getUploadFileInfo().getSize());
                row.createCell(1).setCellValue(img.getAuthor());
                row.createCell(2).setCellValue(img.getUploadFileInfo().getImgrefurl());
                row.createCell(3).setCellValue(img.getFormatDate());
            }
            workbook.write(os);
            os.flush();
            os.close();
        } catch (IOException e) {
            logger.error("", e);
        }

좋은 웹페이지 즐겨찾기