pom
<dependency>?
? ? ?<groupId>com.alibaba</groupId>? ? ? ? ? ? ? ? ? ? ?????<artifactId>easyexcel</artifactId>
? ? ?<version>3.0.5</version>?
</dependency>
3.0.5版本設(shè)置ExportExcelData 類中的邊框設(shè)置使用BorderStyleEnum.THIN
EasyExcel導(dǎo)出?
定義導(dǎo)出類,并設(shè)置樣式
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import com.alibaba.excel.annotation.write.style.ContentStyle;
import com.alibaba.excel.annotation.write.style.HeadRowHeight;
import com.alibaba.excel.annotation.write.style.HeadStyle;
import lombok.Data;
import org.apache.poi.ss.usermodel.BorderStyle;
@Data
@ColumnWidth(25)
@HeadRowHeight(35)
@HeadStyle(fillForegroundColor =9)
@ContentStyle(
verticalAlignment = VerticalAlignmentEnum.CENTER,horizontalAlignment = HorizontalAlignmentEnum.CENTER,
borderTop = BorderStyleEnum.THIN,borderBottom = BorderStyleEnum.THIN,borderLeft = BorderStyleEnum.THIN,borderRight = BorderStyleEnum.THIN)
public class ExportExcelData {
@ExcelProperty("服務(wù)點(diǎn)")
private String fuwudian;
? ? @ExcelIgnore//設(shè)置不導(dǎo)出
private String code1;
? ? @ExcelIgnore//設(shè)置不導(dǎo)出
private String waybill;
? ? @ExcelProperty("寄件人姓名")
private String mail_name;
? ? @ExcelProperty("寄件人電話")
private String mail_phone;
? ? @ExcelProperty("寄件人地址")
private String mail_address;
? ? @ExcelProperty("收件人姓名")
private String addressee_name;
? ? @ExcelProperty("收件人電話")
private String addressee_phone;
? ? @ExcelProperty("收件人地址")
private String addressee_address;
? ? @ExcelProperty("物品信息")
private String goods;
? ? @ExcelProperty("物品重量")
private String weight;
? ? @ExcelProperty("訂單號")
private String number;
? ? @ExcelProperty("價(jià)格")
private String final_money;
? ? @ExcelProperty("狀態(tài)1")
private String state;
? ? @ExcelProperty("狀態(tài)2")
private String state2;
}
導(dǎo)出接口 參數(shù)list:是需要自己在數(shù)據(jù)庫中查詢需要導(dǎo)出的數(shù)據(jù)
@RequestMapping("export")
public void export(HttpServletResponse response,List list){
? ??String fileName =new String("查詢信息表.xlsx".getBytes(), StandardCharsets.ISO_8859_1);
????response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
????response.setCharacterEncoding("utf-8");
????response.setHeader("Content-disposition", "attachment;filename=" + fileName);
try {
????EasyExcel.write(response.getOutputStream(), ExportExcelData.class).sheet("sheet").doWrite(list);
}catch (IOException e) {
????e.printStackTrace();
? ? throw new BusinessException(BusinessStatus.FAIL, "導(dǎo)出失敗");
}
}
verticalAlignment = VerticalAlignmentEnum.CENTER,horizontalAlignment = HorizontalAlignmentEnum.CENTER,