微软雅黑做网站,建设网站视频教程,建设电子商务网站流程,做外贸业务员需要什么条件首先在项目的resources下面建一个template包#xff0c;之后在下面创建一个模版#xff0c;模版格式如下#xff1a;
名称为 financeReportBillStandardTemplateExcel.xlsx#xff1a; {.fee}类型的属性值#xff0c;是下面实体类的属性#xff0c;要注意这里面的格式之后在下面创建一个模版模版格式如下
名称为 financeReportBillStandardTemplateExcel.xlsx {.fee}类型的属性值是下面实体类的属性要注意这里面的格式不能错还需要注意就是驼峰例如{.stockMv}要跟实体类的属性名保持一致否则在导入的时候就会出现null之类的问题。
要是需要给属性设置格式之类的例如我们这里设置千分符并且保留两位小数可进行如下图所示的操作先选中所要设置的单元格然后右键点击选中设置单元格格式就会弹出下图的操作可以进行配置格式 接下来是实体类
package com.citicsc.galaxy.finance.lq;import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;import java.math.BigDecimal;
import java.util.Date;/*** ClassName StandardBillFieldsDTO* Description TODO* Author houbing* Date 2023/9/18 10:07*/Data
Builder
NoArgsConstructor
AllArgsConstructor
public class StandardBillFieldsDTO {private String id;//利息收入(利息归本)private BigDecimal interest;//股息红利private BigDecimal dividend;//资金余额private BigDecimal availableCash;//资产市值private BigDecimal assetMv;//非上市股票市值private BigDecimal unlistedMv;//当日国债逆回购发生额private BigDecimal debtReverseRepurchase;//出入金净额private BigDecimal netCash;//其他资金变动private BigDecimal otherCash;//总资金变动private BigDecimal totalCashInout;//交易费用private BigDecimal fee;//利息收入private BigDecimal interestIncome;//权利金收支private BigDecimal netPremium;//执行实收资金private BigDecimal realReceiveCash;//执行实付资金private BigDecimal realPaymentCash;//现金替代实收资金private BigDecimal realOffsetCashIn;//现金替代实付资金private BigDecimal realOffsetCashOut;//执行冻结资金private BigDecimal frozenCash;//市值权益private BigDecimal totalMv;//股票市值private BigDecimal stockMv;//买券金额private BigDecimal buySecuritiesAmount;//做市商交易经手费优惠private BigDecimal marketDiscount;//累计平仓盈亏private BigDecimal closePnl;//累计浮动盈亏private BigDecimal floatPnl;//其他交易费用private BigDecimal otherFee;}这里只展示部分字段。 接下来就直接在controller层中进行导出
ApiOperation(value 交易账户基础数据查询表)PostMapping(/exportBill)public void exportBill(RequestBody Validated TraAccBillReq req ,HttpServletResponse response) throws Exception {response.setContentType(application/octet-stream);String fileName URLEncoder.encode(交易账户基础数据查询表 DateUtils.formatStr(req.getTradingDay()), utf-8);response.setHeader(Content-disposition, attachment;filename fileName .xlsx);//查询数据库的数据ListStandardBillFieldsDTO dtos lqAppService.queryBillFieldList(req);if (CollectionUtils.isNotEmpty(dtos)) {FillConfig fillConfig FillConfig.builder().forceNewRow(true).build();WriteSheet sheet EasyExcel.writerSheet(0).build();ExcelWriter excelWriter EasyExcel.write(response.getOutputStream()).withTemplate(new ClassPathResource(template/financeReportBillStandardTemplateExcel.xlsx).getInputStream()).build();excelWriter.fill(dtos, fillConfig, sheet);excelWriter.finish();} else {throw new BizException(未查询到账单信息);}}