excel模板來自自己寫死的乙個excel模板,相當於是使用者查詢資料,資料填充到乙個模板的excel裡,再匯出excel
/*建立模板*/
string a= request.getsession().getservletcontext().getrealpath("/resource/河南能源化工集團安全監控系統聯網系統瓦斯湧出異常資訊表.xlsx");
獲取模板
templateexportparams params=new templateexportparams(a);
獲取查詢資料,將資料放到map裡面,自定義的excel的單元格裡獲取map的key值
list> listmap = new arraylist>();
for(int i=0;ima = new hashmap();
ma.put("xh", string.valueof(i+1));
ma.put("mygs", list.get(i).getgs());
ma.put("kjmc", list.get(i).getminename());
ma.put("dd", list.get(i).getlocation());
ma.put("zdz", list.get(i).getnowmaxvalue());
ma.put("zdzsk", list.get(i).getnowtime());
ma.put("three", list.get(i).gettheaybeforevalue());
ma.put("two", list.get(i).gettwodaysagovalue());
ma.put("one", list.get(i).gettheaybeforevalue());
ma.put("nowzdz", list.get(i).getnowmaxvalue());
listmap.add(ma);
}map.put("listmap", listmap);
modelmap.put(templateexcelconstants.file_name, "河南能源化工集團安全監控系統聯網系統瓦斯湧出異常資訊表"); //檔名
modelmap.put(templateexcelconstants.params, params);//引數
modelmap.put(templateexcelconstants.map_data, map);//資料
return templateexcelconstants.jeecg_template_excel_view;//view名稱
springweb中,需要在spring-mvc.xml中引入處理excel的配置
匯出結果
easypoi匯出xlsx型別到excel設定
easypoi匯出xlsx型別到excel,本質上是底層使用的workbook物件不一樣,xlsx使用xssfworkbook物件,所以在構建workbook物件的時候,需要注意使用xssfworkbook。那麼workbook是如何構造出來的呢?翻看easypoi原始碼,如下 public sta...
使用 easypoi 匯出excel
1 使用註解匯出excel 2 使用模板匯出excel 將workbook 寫出到response流中 效果如下 下面是我用到的兩個合併單元格的方法 豎向合併相同單元格,必須保證被合併的需要有兩個及兩個以上的單元格 mapmergemap key 列,value 依賴的列,沒有傳空 startrow...
easypoi 模版匯出
引入包 cn.afterturn groupid easypoi base artifactid 3.2.0 version dependency 在專案目錄新增所要匯出的模版檔案 模版中使用easypoi 提供的模版指令 模板是處理複雜excel的簡單方法,複雜的excel樣式,可以用excel直...