java 匯出到EXCEL
package org.fh.util; import java.util.Date; import java.util.List; import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.poi.hssf.usermodel.HSSFCellStyle; import org.apache.poi.hssf.usermodel.HSSFFont; import org.apache.poi.hssf.usermodel.HSSFRow; import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.ss.usermodel.HorizontalAlignment; import org.apache.poi.ss.usermodel.VerticalAlignment; import org.apache.poi.ss.usermodel.Workbook; import org.fh.entity.PageData; import org.springframework.web.servlet.view.document.AbstractXlsView; /** * 說明:匯出到EXCEL * 作者:FH Admin * from:fhadmin.cn */ public class ObjectExcelView extends AbstractXlsView{ @Override protected void buildExcelDocument(Map<String, Object> model, Workbook workbook, HttpServletRequest request, HttpServletResponse response) throws Exception { // TODO Auto-generated method stub Date date = new Date(); String filename = DateUtil.date2Str(date, "yyyyMMddHHmmss"); HSSFSheet sheet; response.setContentType("application/octet-stream"); response.setHeader("Content-Disposition", "attachment;filename="+filename+".xls"); HSSFWorkbook book = (HSSFWorkbook) workbook; sheet = book.createSheet("sheet1"); List<String> titles = (List<String>) model.get("titles"); int len = titles.size(); HSSFCellStyle headerStyle = book.createCellStyle(); //標題樣式 headerStyle.setAlignment(HorizontalAlignment.CENTER); headerStyle.setVerticalAlignment(VerticalAlignment.CENTER); HSSFFont headerFont = book.createFont(); //標題字型 headerFont.setBold(true); headerFont.setFontHeightInPoints((short)11); headerStyle.setFont(headerFont); short height=25*20; HSSFRow row = sheet.createRow(0); for(int i=0; i<len; i++){ //設定標題 String title = titles.get(i); row.setRowStyle(headerStyle); row.createCell(i).setCellValue(title); } sheet.getRow(0).setHeight(height); HSSFCellStyle contentStyle = book.createCellStyle(); //內容樣式 contentStyle.setAlignment(HorizontalAlignment.CENTER); List<PageData> varList = (List<PageData>) model.get("varList"); int varCount = varList.size(); for(int i=0; i<varCount; i++){ PageData vpd = varList.get(i); HSSFRow rows = sheet.createRow(i+1); for(int j=0;j<len;j++){ String varstr = vpd.getString("var"+(j+1)) != null ? vpd.getString("var"+(j+1)) : ""; rows.setRowStyle(contentStyle); rows.createCell(j).setCellValue(varstr); } } } }
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/31558068/viewspace-2851923/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- hive匯出到csv hive匯出到excelHiveExcel
- fastadmin的匯出到excel功能ASTExcel
- 將資料匯出到ExcelExcel
- Vue+element ui table 匯出到excelVueUIExcel
- 將dataGridView內容匯出到Excel檔案ViewExcel
- Java匯出ExcelJavaExcel
- Excel匯入匯出神器(Java)ExcelJava
- 多個報表匯出到一個 excel 的多 sheet 頁Excel
- 第四節:海量資料匯出到Excel、百萬Excel匯入到DB、秒級/分鐘級排行版Excel
- Dynamics CRM 資料匯出到Excel時列標題不能重複Excel
- java 匯入到EXCEL表格JavaExcel
- java匯出Excel檔案JavaExcel
- java匯出Excel定義匯出模板JavaExcel
- 關於java中Excel的匯入匯出JavaExcel
- Java進行excel的匯入匯出操作JavaExcel
- Java之POI操作Excel表-匯入匯出JavaExcel
- Java POI匯入Excel檔案JavaExcel
- java spring mvc jsp excel 匯入JavaSpringMVCJSExcel
- poi 匯出Excel java程式碼ExcelJava
- java使使用者EasyExcel匯入匯出excelJavaExcel
- MSSQL資料匯出到MYSQLMySql
- java 從EXCEL匯入到系統JavaExcel
- java 從EXCEL匯入到資料庫JavaExcel資料庫
- 大文字資料,匯入匯出到資料庫資料庫
- 資料庫文件編寫,如何通過Navicat把表導成表格?資料庫快速匯出為excel表格資訊,excel匯出到word表格資料庫Excel
- Java之POI操作,封裝ExcelUtil實現Excel匯入匯出Java封裝Excel
- 匯出excelExcel
- Java用策略模式優雅地匯出ExcelJava模式Excel
- Java使用jxl.jar匯出Excel例項JavaJARExcel
- java 匯出 excel 最佳實踐,java 大檔案 excel 避免OOM(記憶體溢位) excel 工具框架JavaExcelOOM記憶體溢位框架
- vue excel匯入匯出VueExcel
- 如何採集地圖上的店鋪把店鋪電話匯出到手機電腦excel地圖Excel
- 如何將simulink的影像匯出到VISIO中
- 如何將資料熱匯出到檔案
- Java與React輕鬆匯出Excel/PDF資料JavaReactExcel
- Angular Excel 匯入與匯出AngularExcel
- VNPY 批量優化引數,並輸出到excel優化Excel
- PHP 匯出 ExcelPHPExcel