天堂国产午夜亚洲专区-少妇人妻综合久久蜜臀-国产成人户外露出视频在线-国产91传媒一区二区三区

當(dāng)前位置:主頁 > 論文百科 > 森林論文 >

POI導(dǎo)入導(dǎo)出Excel模板···

發(fā)布時間:2017-12-24 17:28

  本文關(guān)鍵詞:excel模板路徑  


  更多相關(guān)文章: 導(dǎo)入 導(dǎo)出 Excel 模板


HSSFWorkbook:是操作Excel2003以前(包括2003)的版本,,擴(kuò)展名是.xls

XSSFWorkbook:是操作Excel2007的版本,擴(kuò)展名是.xlsx

以XSSFWorkbook為例:

//導(dǎo)出 public void getExcelByBoiler() { try { /***************沒有模板********************************/ // 第一步,創(chuàng)建一個webbook,對應(yīng)一個Excel文件 XSSFWorkbook work = new XSSFWorkbook(); // 第二步,在webbook中添加一個sheet,對應(yīng)Excel文件中的sheet XSSFSheet sheet = work.createSheet("學(xué)生表一"); // 第三步,在sheet中添加表頭第0行,注意老版本poi對Excel的行數(shù)列數(shù)有限制short XSSFRow row = sheet.createRow((int) 0); // 第四步,創(chuàng)建單元格,并設(shè)置值表頭 設(shè)置表頭居中 XSSFCellStyle style = work.createCellStyle(); style.setAlignment(XSSFCellStyle.ALIGN_CENTER); // 創(chuàng)建一個居中格式 XSSFCell cell = row.createCell((short) 0); cell.setCellValue("學(xué)號"); cell.setCellStyle(style); cell = row.createCell((short) 1); cell.setCellValue("姓名"); cell.setCellStyle(style); /*****************沒有模板END**************************************/ /******************有模板*******************************/ // // 取得excel模板路徑 // String path =ServletActionContext.getServletContext().getRealPath("") // + "/excelTemplate/統(tǒng)計.xlsx"; //這個是我的excel模板 // InputStream in = new FileInputStream(new File(path)); // //取得excel模板 // XSSFWorkbook work = new XSSFWorkbook(in); // // 得到excel的第1張表 // XSSFSheet sheet = work.getSheetAt(0); // // 取得第一行 // XSSFRow row = sheet.getRow(0); // // 取得第一行第一列的單元格 // XSSFCell cell = row.getCell(0); // // 給第一行第一列的單元格設(shè)值 // cell.setCellValue("第一行第一列"); // // 取得第二行 // row = sheet.createRow(1);// 得到行 // cell = row.createCell(0);// 得到第1個單元格 // cell.setCellValue("第二行第一列"); // // cell.setCellStyle(columnOne);// 填充樣式 // // cell = row.createCell(1); // cell.setCellValue("第二行第二列"); // // cell.setCellStyle(columnOne1);// 填充樣式 // row = sheet.createRow(2);// 得到行 // cell = row.createCell(1); // cell.setCellValue("第三行第二列"); /*********************有模板END**********************************/ /*********************顯示圖片**********************************/ //獲取批注對象 // XSSFClientAnchor的參數(shù)說明: // 參數(shù) 說明 // dx1 第1個單元格中x軸的偏移量 // dy1 第1個單元格中y軸的偏移量 // dx2 第2個單元格中x軸的偏移量 // dy2 第2個單元格中y軸的偏移量 // col1 第1個單元格的列號 // row1 第1個單元格的行號 // col2 第2個單元格的列號 // row2 第2個單元格的行號 //(int dx1, int dy1, int dx2, int dy2, short col1, int row1, short col2, int row2) // 顯示圖片 ByteArrayOutputStream byteArrayOut = new ByteArrayOutputStream(); String InputimagePath = ServletActionContext.getServletContext().getRealPath("").concat(FINAL_FOLDER_PATH).concat("20150202175722.png"); BufferedImage bufferImg = ImageIO.read(new File(InputimagePath)); ImageIO.write(bufferImg,"JPG",byteArrayOut); //設(shè)置圖片大小,位置 XSSFClientAnchor anchor = new XSSFClientAnchor(5,0,500,122,(short) 0, 5,(short)10,15); //創(chuàng)建 XSSFDrawing patri = sheet.createDrawingPatriarch(); patri.createPicture(anchor ,work.addPicture(byteArrayOut.toByteArray(), HSSFWorkbook.PICTURE_TYPE_PNG)); // 顯示第二張圖片 byteArrayOut = new ByteArrayOutputStream(); InputimagePath = ServletActionContext.getServletContext().getRealPath("").concat(FINAL_FOLDER_PATH).concat("20150202175754.png"); bufferImg = ImageIO.read(new File(InputimagePath)); ImageIO.write(bufferImg,"JPG",byteArrayOut); //設(shè)置圖片大小,位置 anchor = new XSSFClientAnchor(5,0,500,122,(short) 11, 5,(short)21,15); //創(chuàng)建 patri = sheet.createDrawingPatriarch(); patri.createPicture(anchor ,work.addPicture(byteArrayOut.toByteArray(), HSSFWorkbook.PICTURE_TYPE_PNG)); /*********************顯示圖片END**********************************/ /****************************輸出流*****************************************/ FileOutputStream fout = new FileOutputStream("E:/students.xlsx"); work.write(fout); fout.close(); downLoadFile("E:/students.xlsx"); } catch (FileNotFoundException e) { System.out.println("文件路徑錯誤"); e.printStackTrace(); } catch (IOException e) { System.out.println("文件輸入流錯誤"); e.printStackTrace(); } }
//導(dǎo)入 public void download(String path, HttpServletResponse response) throws IOException { try { // path是指欲下載的文件的路徑。 File file = new File(path); // 取得文件名。 String filename = file.getName(); // 以流的形式下載文件。 InputStream fis = new BoundedInputStream(new FileInputStream(path)); byte[] buffer = new byte[fis.available()]; fis.read(buffer); fis.close(); // 清空response response.reset(); // 設(shè)置response的header response.addHeader("content-disposition", "attachment;filename=" + new String(filename.getBytes())); response.addHeader("content-length", "" + file.length()); OutputStream toclient = new BufferedOutputStream( response.getOutputStream()); response.setContentType("application/vnd.ms-excel ;charset=gb2312"); toclient.write(buffer); toclient.flush(); toclient.close(); } catch (IIOException ex) { ex.printStackTrace(); } } public void downLoadFile(String filePth) { HttpServletResponse response =ServletActionContext.getResponse(); HttpServletRequest request =ServletActionContext.getRequest(); try { //得到當(dāng)前路徑 //StringfilePath=request.getSession().getServletContext().getRealPath(File.separator); File temFile = new File(filePth); //判斷文件是否存在 if(!temFile.exists()){ response.getWriter().write("ERROR:File Not Found"); return ; } //處理文件名得位置(若服務(wù)器為linux和windows的處理方法不同) String fileName =filePth.substring(filePth.lastIndexOf(File.separator)+1); //設(shè)置頭文件,名稱和內(nèi)容的編碼不同,否則會出現(xiàn)亂碼。 response.setHeader("Content-Disposition", "attachment; filename="+new String((fileName).getBytes("gbk"),"UTF-8")); response.setContentType("application/x-download"); OutputStream ot=response.getOutputStream(); BufferedInputStream bis = new BufferedInputStream(new FileInputStream(temFile)); BufferedOutputStream bos = new BufferedOutputStream(ot); byte[] buffer = new byte[4096]; int length = 0; while((length = bis.read(buffer)) > 0){ bos.write(buffer,0,length); } bos.close(); bis.close(); ot.close(); } catch (Exception e) { e.printStackTrace(); } }

本文編號:1329301

資料下載
論文發(fā)表

本文鏈接:http://sikaile.net/wenshubaike/mfmb/1329301.html


Copyright(c)文論論文網(wǎng)All Rights Reserved | 網(wǎng)站地圖 |

版權(quán)申明:資料由用戶40635***提供,本站僅收錄摘要或目錄,作者需要刪除請E-mail郵箱bigeng88@qq.com
欧美精品久久99九九| 精品人妻久久一品二品三品| 欧美尤物在线观看西比尔| 在线一区二区免费的视频| 久久精品伊人一区二区| 国产日韩欧美综合视频| 日韩精品在线观看一区| 国产成人亚洲综合色就色| 国产精品欧美一区两区| 国产在线不卡中文字幕| 中字幕一区二区三区久久蜜桃| 不卡视频免费一区二区三区| 99国产成人免费一区二区| 欧美亚洲美女资源国产| 久久91精品国产亚洲| 久久精品伊人一区二区| 国产一区二区三区香蕉av| 日韩一区中文免费视频| 99久久精品午夜一区| 国产成人精品一区二三区在线观看| 久久99精品日韩人妻| 国产小青蛙全集免费看| 亚洲内射人妻一区二区| 国产不卡的视频在线观看| 日本一本不卡免费视频| 国产美女精品人人做人人爽| 搡老妇女老熟女一区二区| 日韩欧美黄色一级视频| 午夜福利视频六七十路熟女| 欧美日不卡无在线一区| 中文字幕佐山爱一区二区免费| 精品国产成人av一区二区三区| 香蕉久久夜色精品国产尤物| 亚洲淫片一区二区三区| 99久免费精品视频在线观| 午夜精品一区免费视频| 亚洲精品中文字幕熟女| 九九九热视频最新在线| 国产精品一级香蕉一区| 精品日韩av一区二区三区| 国产二级一级内射视频播放|