easypoi的簡單導(dǎo)出 數(shù)據(jù)map導(dǎo)出
官方說明文檔
http://easypoi.mydoc.io/
需要渲染的模版
語法
循環(huán)開始 {{$fe:maplist t.ho
循環(huán)中間參數(shù) t.po
換行]]
循環(huán)結(jié)尾t.amount}}
統(tǒng)計(jì)循環(huán)數(shù)量{{sum:(t.amount)}}
單獨(dú)參數(shù){{totalQuantity}}
常見命令
? 空格分割
? 三目運(yùn)算 {{test ? obj:obj2}} ps:{{QcNum == 0?image:null}}
? n: 表示 這個(gè)cell是數(shù)值類型 {{n:}} ps:{{n:packingNum}}
? le: 代表長度{{le:()}} 在if/else 運(yùn)用{{le:() > 8 ? obj1 : obj2}}
? fd: 格式化時(shí)間 {{fd:(obj;yyyy-MM-dd)}}
? fn: 格式化數(shù)字 {{fn:(obj;###.00)}}
? fe: 遍歷數(shù)據(jù),創(chuàng)建row
? !fe: 遍歷數(shù)據(jù)不創(chuàng)建row
? $fe: 下移插入,把當(dāng)前行,下面的行全部下移.size()行,然后插入
? #fe: 橫向遍歷
? v_fe: 橫向遍歷值
? !if: 刪除當(dāng)前列 {{!if:(test)}}
? 單引號(hào)表示常量值 '' 比如'1' 那么輸出的就是 1
? &NULL& 空格
? ]] 換行符 多行遍歷導(dǎo)出
? sum: 統(tǒng)計(jì)數(shù)據(jù) {{sum:(t.amount)}}
maven
<dependency>
<groupId>cn.afterturn</groupId>
<artifactId>easypoi-base</artifactId>
<version>3.2.0</version>
</dependency>
<dependency>
<groupId>cn.afterturn</groupId>
<artifactId>easypoi-web</artifactId>
<version>3.2.0</version>
</dependency>
<dependency>
<groupId>cn.afterturn</groupId>
<artifactId>easypoi-annotation</artifactId>
<version>3.2.0</version>
</dependency>
過濾的應(yīng)用場景
@RequestMapping("exportExcel")
@SuppressWarnings("unchecked")
@RequiresPermissions("business:product:exportExcel")
public R exportExcel(@RequestBody Map<String, Object> params,ModelMap model,HttpServletRequest request, HttpServletResponse response){
List<ProductEntity> list=new ArrayList<ProductEntity>();//
ExportParams param = new ExportParams("產(chǎn)品信息", "產(chǎn)品信息",ExcelType.XSSF);
if(params.get("ids")!=null){
list=productService.queryListByIds(params.get("ids"));
}else{
list=productService.queryListTwoThousand(params);
}
if(params.get("selected")!=null){
String[] s=params.get("selected").toString().split(",");//前端獲取選中的欄目
List<String> lists =(List<String>) params.get("selected");
List<String> old = new ArrayList<String>();
ProductEntity entity=new ProductEntity();
for (Field field : entity.getClass().getDeclaredFields()) {//去掉選中的欄目
if(!lists.contains(field.getName())){
old.add(field.getName());
}
}
s= old.toArray(new String[1]);//list轉(zhuǎn)數(shù)組
param.setExclusions(s);//過濾沒有選中的欄目導(dǎo)出
}
Workbook workbook = ExcelExportUtil.exportExcel(param, ProductEntity.class,list);
ByteArrayOutputStream fos;
String url="";
try {
fos = new ByteArrayOutputStream();
workbook.write(fos);
url=OSSFactory.build().upload(fos.toByteArray(), OSSConfig.getALI_TEMP()+"excel/product_excel"+System.currentTimeMillis()+".xlsx");
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
if(url.length()>0){
return R.ok().put("url", url).put("msg", "生成成功");
}else{
return R.error().put("msg", "生成失敗");
}
}
這個(gè)是文件上傳阿里云的 順便過濾選中自己想導(dǎo)出不同欄目的喇嘱,接下來看看實(shí)體類
package com.alpha.modules.product.entity;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
import java.util.Map;
import org.hibernate.validator.constraints.NotBlank;
import cn.afterturn.easypoi.excel.annotation.Excel;
/**
* 產(chǎn)品表-pt_product
*
* @author Temple
* @email
* @date 2018-08-08 17:00:09
*/
public class ProductEntity implements Serializable {
private static final long serialVersionUID = 1L;
// ID
@NotBlank(message = "參數(shù)值不能為空")
private Long id;
// 產(chǎn)品名稱
@Excel(name = "產(chǎn)品名稱", orderNum = "2", width = 20)
private String name;
// 產(chǎn)品編號(hào)
@Excel(name = "產(chǎn)品編號(hào)", orderNum = "2", width = 20)
private String code;
// 樣品類別代碼
private String typeCode;
private String typeName;
// 產(chǎn)品分類代碼
private Integer categoryId;
@Excel(name = "產(chǎn)品類別", orderNum = "3", width = 10)
private String categoryName;
// 產(chǎn)品分類備注
private String categoryNote;
// 主題代碼
private String themeCode;
@Excel(name = "產(chǎn)品主題", orderNum = "4", width = 10)
private String themeName;
// 供應(yīng)商代碼
@Excel(name = "工廠代碼", orderNum = "6", width = 10)
private String factoryCode;
// 供應(yīng)商名稱
@Excel(name = "工廠名稱", orderNum = "5", width = 30)
private String factoryName;
// 產(chǎn)品報(bào)價(jià)
@Excel(name = "工廠報(bào)價(jià)", orderNum = "7", width = 10)
private Double price;
// 報(bào)價(jià)幣種
@Excel(name = "幣種", orderNum = "8", width = 10)
private String currency;
// 單位
@Excel(name = "單位", orderNum = "9", width = 10)
private String unit;
// 開發(fā)人用戶名
@Excel(name = "開發(fā)人", orderNum = "10", width = 15)
private String developUser;
// 設(shè)計(jì)人用戶名
@Excel(name = "設(shè)計(jì)人", orderNum = "11", width = 15)
private String designUser;
// 產(chǎn)品材質(zhì)
@Excel(name = "產(chǎn)品材質(zhì)", orderNum = "12", width = 15)
private String material;
// 工廠貨號(hào)
@Excel(name = "工廠貨號(hào)", orderNum = "13", width = 15)
private String factoryNo;
// 產(chǎn)品描述
@Excel(name = "產(chǎn)品描述", orderNum = "14", width = 35)
private String descNote;
// 圖片加密:0不加密绷落,1加密
private Integer encrypt;
// 上傳時(shí)間
@Excel(name = "錄入時(shí)間", orderNum = "15", width = 20,exportFormat="yyyy-MM-dd")
private Date ctime;
// 圖片url
@Excel(name = "產(chǎn)品圖片", orderNum = "1", imageType = 1, type = 2, width = 35, height = 49)
private String picUrl;
// 上傳操作員
@Excel(name = "錄入人員", orderNum = "16", width = 15)
private String cuser;
// 嘜頭
private String mark;
// 狀態(tài):0禁用块攒,1開啟 默認(rèn):0
private Integer state;
// 圖片樣式
private String picStyle;
private Integer isSuit;
private String suitCode;
private String fingerprint;// 指紋信息
private List<Map<String, Object>> suitList;
// 產(chǎn)品類型:0主料,1輔料
private Integer proType;
private String customerCode;
private String topCategory;
private int serialNum;//序列號(hào)
private int filialeId;
}
用注解 包括日期格式 數(shù)字替換文字等
@Excel(name = "錄入時(shí)間", orderNum = "15", width = 20,exportFormat="yyyy-MM-dd")
//時(shí)間格式
@Excel(name = "產(chǎn)品圖片", orderNum = "1", imageType = 1, type = 2, width = 35, height = 49)
//圖片
//數(shù)字替換成文字
@Excel(name = "發(fā)票狀態(tài)", orderNum = "1",replace = { "未推送_0", "已推送_1" }, width = 20)
map封裝導(dǎo)出比較類似
實(shí)體類導(dǎo)出excel 簡單導(dǎo)出
@RequestMapping("/exportPackingReportExcel")
public void exportPackingReportExcel(ModelMap model, @RequestParam Map<String, Object> param,
HttpServletRequest request, HttpServletResponse response) {
ExportParams params = new ExportParams(null, "裝箱單報(bào)表", ExcelType.XSSF);
List<PackingReportCostEntity> dataList =packing.exportPackingReportExcel(param);
model.put(NormalExcelConstants.DATA_LIST, dataList);
model.put(BigExcelConstants.CLASS, PackingReportCostEntity.class);
model.put(BigExcelConstants.PARAMS, params);
model.put(MapExcelConstants.FILE_NAME, "裝箱單報(bào)表");
PoiViewUtil.render(model, request, response, NormalExcelConstants.EASYPOI_EXCEL_VIEW);
}
js文件
//參數(shù)等 這個(gè)是最簡單的導(dǎo)出
window.location.href="/"+T.moduleName+"/packingReport/exportPackingReportExcel?"
導(dǎo)出復(fù)雜的word待續(xù)终佛。朽肥。橙数。激况。