最近2018中文字幕在日韩欧美国产成人片_国产日韩精品一区二区在线_在线观看成年美女黄网色视频_国产精品一区三区五区_国产精彩刺激乱对白_看黄色黄大色黄片免费_人人超碰自拍cao_国产高清av在线_亚洲精品电影av_日韩美女尤物视频网站

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
怎么在SpringBoot中利用POI下載Excel文件

這期內(nèi)容當(dāng)中小編將會給大家?guī)碛嘘P(guān)怎么在SpringBoot中利用POI下載Excel文件,文章內(nèi)容豐富且以專業(yè)的角度為大家分析和敘述,閱讀完這篇文章希望大家可以有所收獲。

創(chuàng)新互聯(lián)公司歡迎咨詢:028-86922220,為您提供成都網(wǎng)站建設(shè)網(wǎng)頁設(shè)計及定制高端網(wǎng)站建設(shè)服務(wù),創(chuàng)新互聯(lián)公司網(wǎng)頁制作領(lǐng)域十載,包括混凝土泵車等多個行業(yè)擁有豐富的網(wǎng)站制作經(jīng)驗,選擇創(chuàng)新互聯(lián)公司,為企業(yè)保駕護航。

1.maven引用


 org.apache.poi
 poi
 3.17

2.service邏輯代碼

 /**
 * 獲取下載模版
 */
 public void salaryTemplate(HttpServletResponse response)throws Exception{
 HSSFWorkbook workbook = new HSSFWorkbook();
 exportExcel(workbook);
 response.setHeader("Content-type","application/vnd.ms-excel");
 
 // 解決導(dǎo)出文件名中文亂碼
 response.setCharacterEncoding("UTF-8");
 response.setHeader("Content-Disposition","attachment;filename="+new String("工資模版".getBytes("UTF-8"),"ISO-8859-1")+".xls");
 workbook.write(response.getOutputStream());
 }
 
 //導(dǎo)入為模版
 private void exportExcel(HSSFWorkbook workbook) throws Exception {
 //創(chuàng)建創(chuàng)建sheet
 HSSFSheet sheet = workbook.createSheet("工資");
 
 //創(chuàng)建單元格樣式
 CellStyle cellStyle = workbook.createCellStyle();
 cellStyle.setFillForegroundColor(HSSFColor.SKY_BLUE.index);
 
 //設(shè)置首行標題標題
 HSSFRow headerRow = sheet.createRow(0);
 headerRow.createCell(0).setCellStyle(cellStyle);
 headerRow.createCell(0).setCellValue("工號");
 headerRow.createCell(1).setCellStyle(cellStyle);
 headerRow.createCell(1).setCellValue("姓名");
 headerRow.createCell(2).setCellStyle(cellStyle);
 headerRow.createCell(2).setCellValue("年齡");
 
 //創(chuàng)建三行數(shù)據(jù)
 HSSFRow row;
 for (int i = 0; i <4; i++) {
 row = sheet.createRow(i + 1);
 row.createCell(0).setCellStyle(cellStyle);
 row.createCell(0).setCellValue(i);
 row.createCell(1).setCellStyle(cellStyle);
 row.createCell(1).setCellValue("張三");
 row.createCell(2).setCellStyle(cellStyle);
 row.createCell(2).setCellValue(19);
 }
 }

3.controller

@GetMapping("/salary/template")
 public void salaryTemplate(HttpServletResponse response)throws Exception{
 salaryService.salaryTemplate(response);
 }

上述就是小編為大家分享的怎么在SpringBoot中利用POI下載Excel文件了,如果剛好有類似的疑惑,不妨參照上述分析進行理解。如果想知道更多相關(guān)知識,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。


名稱欄目:怎么在SpringBoot中利用POI下載Excel文件
轉(zhuǎn)載注明:http://fisionsoft.com.cn/article/pogidh.html