Java制作Excel模板

POI & EasyExcel

POI

Apache POI是Apache软件基金会的开源项目,POI提供API给Java程序对Microsoft Office格式档案读和写的功能。
.NET的开发人员则可以利用NPOI POI for .NET) 来存取 Microsoft Office文档的功能。

EasyExcel

EasyExcel是一个基于Java的简单、省内存的读写Excel的开源项目。
在尽可能节约内存的情况下支持读写百M的Excel。
EasyExcel是阿里的开源项目,使用起来简单方便快捷舒适且优雅,但是功能有限。

使用POI绘制表格

在第一次开发项目中遇到需要批量导出Excel,此时有两个选择:导入Excel填数据和手绘Excel。第一种方法用EasyExcel就可以很方便实现,但是第二种方法只有用POI

(主要是EasyExcel真不会o╥﹏╥)o)

模板

QQ截图20210207105106

Excel模板格式化类

package cn.resico.invoice.excelFromat;

import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.ss.usermodel.BorderStyle;
import org.apache.poi.ss.usermodel.ClientAnchor;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.apache.poi.ss.usermodel.VerticalAlignment;
import org.apache.poi.ss.util.CellRangeAddress;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

class Excel {

    //测试DTO
    CreatDTO creatDTO = new CreatDTO);

    //开始列
    private final int startColumn = 1;
    //开始行
    private final int startRow = 0;
    //固定行高 分别表示标题行高,正文行高,“注~”栏行高
    private final int titleRowHeight = 885, rowHeight = 815, rowHeightMessage = 270, rowHeightIdCard = 450;
    //固定列宽
    private final double[] colWidths = {5.63, 21.25, 16.38, 10.25, 9.13, 16.13, 11.5, 27.13};
    //字体设置
    private final int textFontSize = 14, smallTitleFontSize = 14, bigTitleFontSIze = 18;
    //间隔符号设置
    private final String interval = " ";


    public HSSFWorkbook workbook;
    public HSSFSheet sheet;

    /**
     * 设置列宽
     *
     * @param
     * @return
     */
    private void setColumnWidth) {
        //比例 本来应该是256但不知道为何存在误差,此处根据误差比例进行调整
        final int scale = 296;

        for int i = 0; i < colWidths.length; i++) {
            sheet.setColumnWidthi, int) scale * colWidths[i]));
        }
    }

    /**
     * 对单元格进行合并同时进行边框处理(避免合并单元格后部分单元格没有边框)
     *
     * @param
     * @return
     */
    private void setMergedBorderHSSFCellStyle style, HSSFRow rows, int col1, int col2) {
        for int i = col1 + 1; i <= col2; i++) {
            HSSFCell hssfCell = rows.createCelli);
            hssfCell.setCellStylestyle);
            hssfCell.setCellValue"");
        }
    }

    /**
     * 创建行元素.
     *
     * @param style  样式
     * @param height 行高
     * @param value  行显示的内容
     * @param row1   起始行
     * @param row2   结束行
     * @param col1   起始列
     * @param col2   结束列
     */
    private void createRowHSSFCellStyle style, int height, String value, int row1, int row2, int col1, int col2) {
        sheet.addMergedRegionnew CellRangeAddressrow1, row2, col1, col2));  //设置从第row1行合并到第row2行,第col1列合并到col2列
        HSSFRow rows = sheet.createRowrow1);//设置第几行
        setMergedBorderstyle, rows, col1, col2); //进行合并后边框处理
        rows.setHeightshort) height);              //设置行高
        HSSFCell cell = rows.createCellcol1);       //设置内容开始的列
        cell.setCellStylestyle);                    //设置样式
        cell.setCellValuevalue);                    //设置该行的值

    }

    /**
     * 创建样式
     *
     * @param fontSize 字体大小
     * @param align    水平位置  左右居中2 居右3 默认居左 垂直均为居中
     * @param bold     是否加粗
     * @return
     */
    private HSSFCellStyle getStyleint fontSize, int align, boolean bold, boolean border) {
        HSSFFont font = workbook.createFont);
        font.setFontName"宋体");
        font.setFontHeightInPointsshort) fontSize);// 字体大小
        font.setBoldbold);
        HSSFCellStyle style = workbook.createCellStyle);
        style.setFontfont);                         //设置字体
        style.setWrapTexttrue);
        switch align) {                             // 居左1 居中2 居右3 默认居左
//            case 1:style.setAlignmentHorizontalAlignment.LEFT);break;
            case 2:
                style.setAlignmentHorizontalAlignment.CENTER);
                break;
            case 3:
                style.setAlignmentHorizontalAlignment.RIGHT);
                break;
        }

        style.setVerticalAlignmentVerticalAlignment.CENTER);// 上下居中1
        if border) {
            style.setBorderRightBorderStyle.THIN);
            style.setBorderLeftBorderStyle.THIN);
            style.setBorderBottomBorderStyle.THIN);
            style.setBorderTopBorderStyle.THIN);
            style.setLockedtrue);
        }
        return style;
    }

    /**
     * 用设置表格格式生成固定表格,思路是一行一行进行建表
     * 注意:
     * 对于同一行中多个信息:&表示信息填写在同一格  /表示信息填写在不同格
     *
     * @param
     * @param
     */
    public void createFormat) throws IOException {
        //设置列宽
        setColumnWidth);
        //表格大标题常用格式
        HSSFCellStyle styleBigTitleCommon = getStylebigTitleFontSIze, 2, true, false);
        //表格小标题常用格式
        HSSFCellStyle styleSmallTitleCommon = getStylesmallTitleFontSize, 2, true, true);
        //表格固定方框内常用格式
        HSSFCellStyle styleFixedCommon = getStyletextFontSize, 2, true, true);
        //表格填写方框内常用格式
        HSSFCellStyle styleWriteCommon = getStyletextFontSize, 2, true, true);

        //当前行数(每次完成一行构建就++)
        int currentRow = startRow;

        /**
         * 第一行:标题
         */
        createRowstyleBigTitleCommon, titleRowHeight, "Excel导出测试表", currentRow, currentRow, startColumn, startColumn + 6);
        currentRow++;
        /**
         * 第二行:自然人信息
         */
        createRowstyleSmallTitleCommon, rowHeight, "自然人信息", currentRow, currentRow, startColumn, startColumn + 6);
        currentRow++;

        /**
         * 第三行:名字/联系电话
         */
        HSSFRow row3 = sheet.createRowcurrentRow);
        row3.setHeightshort) rowHeight);
        //姓名
        HSSFCell cellName = row3.createCellstartColumn);
        cellName.setCellStylestyleFixedCommon);
        cellName.setCellValue"姓名");
        //姓名填写栏
        sheet.addMergedRegionnew CellRangeAddresscurrentRow, currentRow, startColumn + 1, startColumn + 3));
        setMergedBorderstyleWriteCommon, row3, startColumn + 1, startColumn + 3);
        HSSFCell cellOfName = row3.createCellstartColumn + 1);
        cellOfName.setCellStylestyleWriteCommon);
        cellOfName.setCellValuecreatDTO.getName));

        //联系电话
        row3.setHeightshort) rowHeight);
        HSSFCell cellMobileOFDrawer = row3.createCellstartColumn + 4);
        cellMobileOFDrawer.setCellStylestyleFixedCommon);
        cellMobileOFDrawer.setCellValue"联系电话");
        //联系电话填写栏
        sheet.addMergedRegionnew CellRangeAddresscurrentRow, currentRow, startColumn + 5, startColumn + 6));
        setMergedBorderstyleWriteCommon, row3, startColumn + 5, startColumn + 6);
        HSSFCell cellOfMobileOfDrawer = row3.createCellstartColumn + 5);
        cellOfMobileOfDrawer.setCellStylestyleWriteCommon);
        cellOfMobileOfDrawer.setCellValuecreatDTO.getMobileOfDrawer));
        currentRow++;

        /**
         * 第四行:身份证号
         */
        HSSFRow row4 = sheet.createRow3);
        row4.setHeightshort) rowHeight);
        //身份证号
        HSSFCell cellIdNo = row4.createCellstartColumn);
        cellIdNo.setCellStylestyleFixedCommon);
        cellIdNo.setCellValue"身份证号码");
        //身份证号填写栏
        sheet.addMergedRegionnew CellRangeAddresscurrentRow, currentRow, startColumn + 1, startColumn + 6));
        setMergedBorderstyleWriteCommon, row4, startColumn + 1, startColumn + 6);
        HSSFCell cellOfIdNo = row4.createCellstartColumn + 1);
        cellOfIdNo.setCellStylestyleWriteCommon);
        cellOfIdNo.setCellValuecreatDTO.getIdNo));
        currentRow++;

        /**
         * 第五行:购买方信息
         */
        createRowstyleSmallTitleCommon, rowHeight, "购买方信息", currentRow, currentRow, startColumn, startColumn + 6);
        currentRow++;

        /**
         * 第六行:公司名称/纳税人识别号
         */
        HSSFRow row6 = sheet.createRowcurrentRow);
        row6.setHeightshort) rowHeight);
        //公司名称
        HSSFCell cellCompanyName = row6.createCellstartColumn);
        cellCompanyName.setCellStylestyleFixedCommon);
        cellCompanyName.setCellValue"公司名称");
        //公司名称填写栏
        sheet.addMergedRegionnew CellRangeAddresscurrentRow, currentRow, startColumn + 1, startColumn + 3));
        setMergedBorderstyleWriteCommon, row6, startColumn + 1, startColumn + 3);
        HSSFCell cellOfCompanyName = row6.createCellstartColumn + 1);
        cellOfCompanyName.setCellStylestyleWriteCommon);
        cellOfCompanyName.setCellValuecreatDTO.getCompanyName));

        //纳税人识别号
        HSSFCell cellIdentificationNumber = row6.createCellstartColumn + 4);
        cellIdentificationNumber.setCellStylestyleFixedCommon);
        cellIdentificationNumber.setCellValue"纳税人识别号");
        //纳税人识别号填写栏
        sheet.addMergedRegionnew CellRangeAddresscurrentRow, currentRow, startColumn + 5, startColumn + 6));
        setMergedBorderstyleWriteCommon, row6, startColumn + 5, startColumn + 6);
        HSSFCell cellOfIdentificationNumber = row6.createCellstartColumn + 5);
        cellOfIdentificationNumber.setCellStylestyleWriteCommon);
        cellOfIdentificationNumber.setCellValuecreatDTO.getIdentificationNumber));
        currentRow++;

        /**
         * 第七行:地址&联系电话
         */
        HSSFRow row7 = sheet.createRowcurrentRow);
        row7.setHeightshort) rowHeight);
        //地址&联系电话
        HSSFCell cellAddressAndMobileOfHead = row7.createCellstartColumn);
        cellAddressAndMobileOfHead.setCellStylestyleFixedCommon);
        cellAddressAndMobileOfHead.setCellValue"地址&联系电话");
        //地址&联系电话填写栏
        sheet.addMergedRegionnew CellRangeAddresscurrentRow, currentRow, startColumn + 1, startColumn + 6));
        setMergedBorderstyleWriteCommon, row7, startColumn + 1, startColumn + 6);
        HSSFCell cellOfAddressAndMobileOfHead = row7.createCellstartColumn + 1);
        cellOfAddressAndMobileOfHead.setCellStylestyleWriteCommon);
        cellOfAddressAndMobileOfHead.setCellValuecreatDTO.getAddress) + interval + creatDTO.getMobileOfHead));
        currentRow++;

        /**
         * 第八行:开户行&银行账号
         */
        HSSFRow row8 = sheet.createRowcurrentRow);
        row8.setHeightshort) rowHeight);
        //开户行&银行账号
        HSSFCell cellBankNameAndBankAccount = row8.createCellstartColumn);
        cellBankNameAndBankAccount.setCellStylestyleFixedCommon);
        cellBankNameAndBankAccount.setCellValue"开户行&银行账号");
        //开户行&银行账号填写栏
        sheet.addMergedRegionnew CellRangeAddresscurrentRow, currentRow, startColumn + 1, startColumn + 6));
        setMergedBorderstyleWriteCommon, row8, startColumn + 1, startColumn + 6);
        HSSFCell cellOfBankNameAndBankAccount = row8.createCellstartColumn + 1);
        cellOfBankNameAndBankAccount.setCellStylestyleWriteCommon);
        cellOfBankNameAndBankAccount.setCellValuecreatDTO.getBankName) + interval + creatDTO.getBankAccount));
        currentRow++;

        /**
         * 第九行+第十行 ~ 第N行+第N+1行:开票内容相关
         * 注意:
         *      此处命名统一以第9/10行为规范。
         */
        //开票内容包含几行
        for CreatDTO.OrderItemPO itemPO : creatDTO.getOrderItems)) {
            HSSFRow row9 = sheet.createRowcurrentRow);
            row9.setHeightshort) rowHeight);
            //开票内容
            HSSFCell cellInvoiceContent = row9.createCellstartColumn);
            cellInvoiceContent.setCellStylestyleFixedCommon);
            cellInvoiceContent.setCellValue"开票内容");
            //开票内容填写栏
            sheet.addMergedRegionnew CellRangeAddresscurrentRow, currentRow, startColumn + 1, startColumn + 6));
            setMergedBorderstyleWriteCommon, row9, startColumn + 1, startColumn + 6);
            HSSFCell cellOfInvoiceContent = row9.createCellstartColumn + 1);
            cellOfInvoiceContent.setCellStylestyleWriteCommon);
            cellOfInvoiceContent.setCellValueitemPO.getRemark));
            currentRow++;

            HSSFRow row10 = sheet.createRowcurrentRow);
            row10.setHeightshort) rowHeight);
            //规格型号
            HSSFCell cellSpecs = row10.createCellstartColumn);
            cellSpecs.setCellStylestyleFixedCommon);
            cellSpecs.setCellValue"规格型号:" + itemPO.getSpecs));
            //计量单位
            sheet.addMergedRegionnew CellRangeAddresscurrentRow, currentRow, startColumn + 1, startColumn + 2));
            setMergedBorderstyleWriteCommon, row10, startColumn + 1, startColumn + 2);
            HSSFCell cellUnit = row10.createCellstartColumn + 1);
            cellUnit.setCellStylestyleWriteCommon);
            cellUnit.setCellValue"计量单位:" + itemPO.getUnit));
            //数量
            sheet.addMergedRegionnew CellRangeAddresscurrentRow, currentRow, startColumn + 3, startColumn + 4));
            setMergedBorderstyleWriteCommon, row10, startColumn + 3, startColumn + 4);
            HSSFCell cellCount = row10.createCellstartColumn + 3);
            cellCount.setCellStylestyleWriteCommon);
            cellCount.setCellValue"数量:" + itemPO.getCount));
            //开票金额
            sheet.addMergedRegionnew CellRangeAddresscurrentRow, currentRow, startColumn + 5, startColumn + 6));
            setMergedBorderstyleWriteCommon, row10, startColumn + 5, startColumn + 6);
            HSSFCell cellInvoiceAmt = row10.createCellstartColumn + 5);
            cellInvoiceAmt.setCellStylestyleWriteCommon);
            cellInvoiceAmt.setCellValue"开票金额:" + itemPO.getInvoiceAmt));
            currentRow++;
        }

        /**
         * 第N+2行:收款人/复核人
         */
        HSSFRow row11 = sheet.createRowcurrentRow);
        row11.setHeightshort) rowHeight);
        //收款人
        sheet.addMergedRegionnew CellRangeAddresscurrentRow, currentRow, startColumn, startColumn + 3));
        setMergedBorderstyleWriteCommon, row11, startColumn, startColumn + 3);
        HSSFCell cellPayee = row11.createCellstartColumn);
        cellPayee.setCellStylestyleWriteCommon);
        cellPayee.setCellValue"收款人:" + creatDTO.getName));
        //复核人
        sheet.addMergedRegionnew CellRangeAddresscurrentRow, currentRow, startColumn + 4, startColumn + 6));
        setMergedBorderstyleWriteCommon, row11, startColumn + 4, startColumn + +6);
        HSSFCell cellReviewer = row11.createCellstartColumn + 4);
        cellReviewer.setCellStylestyleWriteCommon);
        cellReviewer.setCellValue"复核人:" + creatDTO.getName));
        currentRow++;

        /**
         * 第N+3行:备注栏
         */
        HSSFRow row12 = sheet.createRowcurrentRow);
        row12.setHeightshort) rowHeight);
        //备注栏
        HSSFCell cellRemarks = row12.createCellstartColumn);
        cellRemarks.setCellStylestyleFixedCommon);
        cellRemarks.setCellValue"备注栏");
        //备注栏填写栏
        sheet.addMergedRegionnew CellRangeAddresscurrentRow, currentRow, startColumn + 1, startColumn + 6));
        setMergedBorderstyleWriteCommon, row12, startColumn + 1, startColumn + 6);
        HSSFCell cellOfRemarks = row12.createCellstartColumn + 1);
        cellOfRemarks.setCellStylestyleWriteCommon);
        cellOfRemarks.setCellValuecreatDTO.getRemark));
        currentRow++;

        /**
         * 第N+4行:邮寄信息
         */
        createRowstyleSmallTitleCommon, rowHeight, "邮寄信息", currentRow, currentRow, startColumn, startColumn + 6);
        currentRow++;

        /**
         * 第N+5行:收件地址&联系人&电话
         */
        HSSFRow row14 = sheet.createRowcurrentRow);
        row14.setHeightshort) rowHeight);
        //收件地址&联系人&电话
        HSSFCell cellReceivedAddressContactsMobileOfContacts = row14.createCellstartColumn);
        cellReceivedAddressContactsMobileOfContacts.setCellStylestyleFixedCommon);
        cellReceivedAddressContactsMobileOfContacts.setCellValue"收件地址&联系人&电话");
        //收件地址&联系人&电话填写栏
        sheet.addMergedRegionnew CellRangeAddresscurrentRow, currentRow, startColumn + 1, startColumn + 6));
        setMergedBorderstyleWriteCommon, row14, startColumn + 1, startColumn + 6);
        HSSFCell cellOfReceivedAddressContactsMobileOfContacts = row14.createCellstartColumn + 1);
        cellOfReceivedAddressContactsMobileOfContacts.setCellStylestyleWriteCommon);
        cellOfReceivedAddressContactsMobileOfContacts.setCellValuecreatDTO.getReceivedAddress) + interval + creatDTO.getContacts) + interval + creatDTO.getMobileOfContacts));
        currentRow++;

        /**
         * 第N+6行:发件联系人&电话
         */
        HSSFRow row15 = sheet.createRowcurrentRow);
        row15.setHeightshort) rowHeight);
        //发件联系人&电话
        HSSFCell cellSendContactsMobileSendContacts = row15.createCellstartColumn);
        cellSendContactsMobileSendContacts.setCellStylestyleFixedCommon);
        cellSendContactsMobileSendContacts.setCellValue"发件联系人&电话");
        //发件联系人&电话填写栏
        sheet.addMergedRegionnew CellRangeAddresscurrentRow, currentRow, startColumn + 1, startColumn + 6));
        setMergedBorderstyleWriteCommon, row15, startColumn + 1, startColumn + 6);
        HSSFCell cellOfSendContactsMobileSendContacts = row15.createCellstartColumn + 1);
        cellOfSendContactsMobileSendContacts.setCellStylestyleWriteCommon);
        cellOfSendContactsMobileSendContacts.setCellValuecreatDTO.getSendContacts) + interval + creatDTO.getMobileSendContacts));
        currentRow++;

        /**
         * 第N+7行:注~
         */
        HSSFRow row16 = sheet.createRowcurrentRow);
        row16.setHeightshort) rowHeightMessage);
        HSSFCellStyle styleMessage = getStyle11, 1, true, false);
        sheet.addMergedRegionnew CellRangeAddresscurrentRow, currentRow, startColumn, startColumn + 3));
        HSSFCell cellMessage = row16.createCellstartColumn);
        cellMessage.setCellStylestyleMessage);
        cellMessage.setCellValue"注:以上除备注栏和发件联系人外均为必填项");
        currentRow++;


        /**
         * 隔一行
         */
        sheet.createRowcurrentRow).setHeightshort) rowHeightMessage);
        currentRow++;

        /**
         * 身份证图片栏
         */
        for int i = 0; i < 10; i++) {
            sheet.createRowcurrentRow).setHeightshort) 450);
            currentRow++;
        }
        sheet.addMergedRegionnew CellRangeAddresscurrentRow - 10, currentRow - 1, startColumn, startColumn + 3));
        sheet.addMergedRegionnew CellRangeAddresscurrentRow - 10, currentRow - 1, startColumn + 4, startColumn + 6));

        ByteArrayOutputStream byteArrayOutFront = new ByteArrayOutputStream);
        BufferedImage bufferImgFront = ImageIO.readnew File"C:\Users\Yuri\Desktop\front.png"));
        ImageIO.writebufferImgFront, "jpg", byteArrayOutFront);

        ByteArrayOutputStream byteArrayOutBack = new ByteArrayOutputStream);
        BufferedImage bufferImgBack = ImageIO.readnew File"C:\Users\Yuri\Desktop\back.jpg"));
        ImageIO.writebufferImgBack, "jpg", byteArrayOutBack);

        HSSFPatriarch patriarch = sheet.createDrawingPatriarch);
        //anchor主要用于设置图片的属性
        HSSFClientAnchor anchorFront = new HSSFClientAnchor0, 0, 1000, 255, short) startColumn, currentRow - 10, short) startColumn + 3), currentRow - 1);
        HSSFClientAnchor anchorBack = new HSSFClientAnchor0, 0, 1000, 255, short) startColumn + 4), currentRow - 10, short) startColumn + 6), currentRow - 1);
        anchorFront.setAnchorTypeClientAnchor.AnchorType.byId3));
        anchorBack.setAnchorTypeClientAnchor.AnchorType.byId3));
        //插入图片
        patriarch.createPictureanchorFront, workbook.addPicturebyteArrayOutFront.toByteArray), HSSFWorkbook.PICTURE_TYPE_EMF));
        patriarch.createPictureanchorBack, workbook.addPicturebyteArrayOutBack.toByteArray), HSSFWorkbook.PICTURE_TYPE_EMF));
    }

    public static void mainString[] args) throws IOException {
        Excel excel = new Excel);
        excel.workbook = new HSSFWorkbook);
        excel.sheet = excel.workbook.createSheet"Akira");
        excel.createFormat);
        File outPutFile = new File"C:\Users\Yuri\Desktop\模板测试.xls");
        outPutFile.createNewFile);
        FileOutputStream out = new FileOutputStreamoutPutFile);
        excel.workbook.writeout);
        out.flush);
        out.close);
    }
}


注入数据DTO

package cn.resico.invoice.excelFromat;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author Yuri
 * @Date 2020/12/14 14:03
 * @Version 1.0
 * @Description:
 */
@Data
public class CreatDTO {

    @ApiModelPropertyvalue = "开票人姓名")
    private String name;

    @ApiModelPropertyvalue = "开票人电话")
    private String mobileOfDrawer;

    @ApiModelPropertyvalue = "开票人身份证")
    private String idNo;

    @ApiModelPropertyvalue = "收货地址")
    private String address;

    @ApiModelPropertyvalue = "公司名称")
    private String companyName;

    @ApiModelPropertyvalue = "纳税人识别号")
    private String identificationNumber;

    @ApiModelPropertyvalue = "公司电话")
    private String mobileOfHead;

    @ApiModelPropertyvalue = "开户行名称")
    private String bankName;

    @ApiModelPropertyvalue = "公司账户")
    private String BankAccount;

    @ApiModelPropertyvalue = "开票内容")
    private List<OrderItemPO> OrderItems;

    @ApiModelPropertyvalue = "联系人")
    private String contacts;

    @ApiModelPropertyvalue = "联系人电话")
    private String mobileOfContacts;

    @ApiModelPropertyvalue = "发件人")
    private String sendContacts;

    @ApiModelPropertyvalue = "发件人电话")
    private String mobileSendContacts;

    @ApiModelPropertyvalue = "项目名称")
    private String projectName;

    @ApiModelPropertyvalue = "项目地址")
    private String projectAddress;

    @ApiModelPropertyvalue = "收货地址")
    private String receivedAddress;

    @ApiModelPropertyvalue = "备注")
    private String remark;

    public CreatDTO) {
        setName"萧瑟");
        setMobileOfDrawer"1529817555");
        setIdNo"51033219990505152436");
        setCompanyName"殉");
        setIdentificationNumber"12345678910");
        setAddress"亚马逊拉斯特拉山脉");
        setMobileOfHead"0087541");
        setBankName"秋明财团");
        setBankAccount"01511544");
        setOrderItemsnew ArrayList<>));
        setProjectName"天蝎计划");
        setProjectAddress"南天球的黄道带");
        setReceivedAddress"银河系地对月发射中心");
        setContacts"天蝎座");
        setMobileOfContacts"0706");
        setSendContacts"巨蟹座");
        setMobileSendContacts"9913");
        setRemark"没有什么好备注就随便写写吧");

        OrderItemPO itemPO = new OrderItemPO);
        itemPO.setRemark"黄道天蝎");
        itemPO.setSpecs"SR");
        itemPO.setUnit"平方度");
        itemPO.setCountBigDecimal.valueOf9000));
        itemPO.setInvoiceAmtBigDecimal.valueOf6554848));
        getOrderItems).additemPO);
        OrderItemPO itemPO2 = new OrderItemPO);
        itemPO2.setRemark"三体");
        itemPO2.setSpecs"SSS");
        itemPO2.setUnit"光年");
        itemPO2.setCountBigDecimal.valueOf4));
        itemPO2.setInvoiceAmtBigDecimal.valueOf984545214));
        getOrderItems).additemPO2);
    }

    @Data
    public static class OrderItemPO {
        @ApiModelPropertyvalue = "交易号")
        private Long orderId;

        @ApiModelPropertyvalue = "开票内容")
        private String remark;

        @ApiModelPropertyvalue = "规格")
        private String specs;

        @ApiModelPropertyvalue = "计量单位")
        private String unit;

        @ApiModelPropertyvalue = "数量")
        private BigDecimal count;

        @ApiModelPropertyvalue = "单价")
        private BigDecimal unitPrice;

        @ApiModelPropertyvalue = "开票金额")
        private BigDecimal invoiceAmt;
    }
}

以上是第一次做模板的代码,所以很多地方写的都是小心翼翼的,但熟悉后其实很多一样格式的行可以用循环就生成了。

以上代码是没有任何技术可言的,但是对于未接触过这方面的人来说,在初次接到这种需求需要知道什么技术可以实现。

Published by

风君子

独自遨游何稽首 揭天掀地慰生平

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注