• java 一对多导出excel


    pom

            <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>
    import cn.afterturn.easypoi.excel.annotation.ExcelCollection;
    import com.huitian.mine.domain.SurveyDetailComplete;
    import lombok.Data;
    import cn.afterturn.easypoi.excel.annotation.Excel;
    
    import java.io.Serializable;
    import java.util.List;
    
    @Data
    public class ExportTemplateExcelOne implements Serializable {
    
        private static final long serialVersionUID = 1L;
    
        @Excel(name = "序号",needMerge = true,width = 20)
        private String id;
    
        @Excel(name = "统一编号",needMerge = true,width = 20)
        private String mineNumber;
    
        @Excel(name = "历史遗留矿山名称",needMerge = true,width = 20)
        private String mineName;
    
        //@Excel(name = "遥感图斑编号",needMerge = true)
        private String remoteSensingSpotNumber;
    
        @Excel(name = "主要开采矿种",needMerge = true,width = 20)
        private String mineType;
    
        @Excel(name = "开采方式",needMerge = true,width = 20)
        private String miningWay;
    
        @Excel(name = "废弃原因",needMerge = true,width = 20)
        private String abandonReason;
    
        @Excel(name = "矿山地址",needMerge = true,width = 20)
        private String villageTown;
    
        @Excel(name = "经度",needMerge = true,width = 20)
        private String centerPositionLongitude;
    
        @Excel(name = "纬度",needMerge = true,width = 20)
        private String centerPositionLatitude;
    
        @ExcelCollection(name = "")
        private List<SurveyDetailComplete> surveyDetailCompleteList;
    
    }
    
    
    import cn.afterturn.easypoi.excel.annotation.Excel;
    @Data
    public class SurveyDetailComplete {
        /**系统生成ID*/
        @TableId(type = IdType.ID_WORKER_STR)
        private String id;
        /**矿山ID*/
        //@Excel(name = "矿山ID", width = 15)
        private String mineId;
        /**图斑号*/
        @Excel(name = "图斑号", width = 25)
        private String remoteSensingSpotNumber;
        /**修复方式及面积-自然修复*/
        @Excel(name = "修复方式及面积-自然修复", width = 15)
        private String naturalRepair;
        /**修复方式及面积-人工修复*/
        @Excel(name = "修复方式及面积-人工修复", width = 15)
        private String artificialRepairArea;
        /**修复方式及面积-投入资金(万元)*/
        @Excel(name = "修复方式及面积-投入资金(万元)", width = 15)
        private String investedCapital;
        /**修复土地资源-耕地*/
        @Excel(name = "修复土地资源-耕地", width = 15)
        private String arableLand;
        /**修复土地资源-种植园用地*/
        @Excel(name = "修复土地资源-种植园用地", width = 15)
        private String plantationLand;
        /**修复土地资源-林地*/
        @Excel(name = "修复土地资源-林地", width = 15)
        private String woodLand;
        /**修复土地资源-草地*/
        @Excel(name = "修复土地资源-草地", width = 15)
        private String grassLand;
        /**修复土地资源-建设用地*/
        @Excel(name = "修复土地资源-建设用地", width = 15)
        private String constructionLand;
        /**修复土地资源-其他用地*/
        @Excel(name = "修复土地资源-其他用地", width = 15)
        private String otherLand;
        /**修复土地资源-小计*/
        @Excel(name = "修复土地资源-小计", width = 15)
        private String landSubtotal;
    
    }
    @RequestMapping(value = "/complete", method = RequestMethod.POST)
        public Result exportXlsComplete(@RequestParam(name = "selectRegionCode", defaultValue = "") String selectRegionCode,
                                        @RequestParam(name = "selectRegionType", defaultValue = "") String selectRegionType, HttpServletResponse response) throws Exception {
            Map<String, Object> paramsMap = this.getRegionCodeAndFileName(selectRegionCode, selectRegionType);
            //查询一对多数据
            List<ExportTemplateExcelOne> list = exportExcelMapper.exportExcelOne(String.valueOf(paramsMap.get("selectRegionCode")));       
            // 简单模板导出方法
            cn.afterturn.easypoi.excel.entity.ExportParams params = new cn.afterturn.easypoi.excel.entity.ExportParams();
            params.setTitle("历史遗留矿山调查基本情况表(已治理的)");//设置表头
            params.setSheetName("已治理(含自然修复)");//设置sheet名
            Workbook workbook = ExcelExportUtil.exportExcel(params, ExportTemplateExcelOne.class, list);
            this.setExportExcelFormat(response, workbook, "历史遗留矿山调查基本情况表(已治理的)");
            return new Result().ok();
        }
    /**
    * 响应数据
    * @param response
    * @param workbook
    * @param fileName
    * @throws Exception
    */
    public void setExportExcelFormat(HttpServletResponse response, Workbook workbook, String fileName) throws Exception {
    response.setHeader("Content-Disposition", "attachment;filename=" + new String(fileName.getBytes(), "ISO8859-1"));
    response.setHeader("Pargam", "no-cache");
    response.setHeader("Cache-Control", "no-cache");
    ServletOutputStream outStream = null;
    try {
    outStream = response.getOutputStream();
    workbook.write(outStream);
    } finally {
    outStream.flush();
    outStream.close();
    }
    }


    List<ExportTemplateExcelOne> exportExcelOne(@Param("regionCode") String regionCode);
    <resultMap id="completeBean" type="com.xxxxx.mine.domain.vo.ExportTemplateExcelOne">
            <id column="id" property="id"></id>
            <result column="mine_number" property="mineNumber"></result>
            <result column="mine_name" property="mineName"></result>
            <result column="remote_sensing_spot_number" property="remoteSensingSpotNumber"></result>
            <result column="mine_type" property="mineType"></result>
            <result column="mining_way" property="miningWay"></result>
            <result column="abandon_reason" property="abandonReason"></result>
            <result column="village_town" property="villageTown"></result>
            <result column="center_position_longitude" property="centerPositionLongitude"></result>
            <result column="center_position_latitude" property="centerPositionLatitude"></result>
    
            <collection property="surveyDetailCompleteList" ofType="com.xxxx.mine.domain.SurveyDetailComplete">
                <id column="cid" property="id"></id>
                <result column="mine_id" property="mineId"></result>
                <result column="natural_repair" property="naturalRepair"></result>
                <result column="artificial_repair_area" property="artificialRepairArea"></result>
                <result column="invested_capital" property="investedCapital"></result>
                <result column="arable_land" property="arableLand"></result>
                <result column="plantation_land" property="plantationLand"></result>
                <result column="wood_land" property="woodLand"></result>
                <result column="grass_land" property="grassLand"></result>
                <result column="construction_land" property="constructionLand"></result>
                <result column="other_land" property="otherLand"></result>
                <result column="land_subtotal" property="landSubtotal"></result>
                <result column="spotNumber" property="remoteSensingSpotNumber"></result>
            </collection>
        </resultMap>
        <select id="exportExcelOne" parameterType="java.lang.String"
                resultMap="completeBean">
            select t.* ,tc.id cid, tc.*,tc.remote_sensing_spot_number spotNumber
            FROM t_o_mines_data t LEFT JOIN t_o_survey_detail_complete tc ON t.id=tc.mine_id
            WHERE t.sys_org_code
            <if test="regionCode.length()==2">
                like CONCAT(#{regionCode},'%')
            </if>
            <if test="regionCode.length()==4">
                like CONCAT(#{regionCode},'%')
            </if>
            <if test="regionCode.length()==6">
                = #{regionCode}
            </if>
            and del_flag='0'
            order by t.id asc;
    
        </select>

    vue 前端

     fileSaver.saveAs(response.data, '附表1-云南省历史遗留矿山调查基本情况表(已治理的).xls', true)

    导出效果

  • 相关阅读:
    几种排序(c#实现)
    仿 MVC 三大特性
    自定义顺序表ArrayList
    MSMQ消息队列
    IIS 负载均衡(ARR)
    AOP 编程
    SqlServer 存储过程
    mac下mysql5.7.10密码问题
    gearman参数说明
    增加响应header让ajax支持跨域
  • 原文地址:https://www.cnblogs.com/yscec/p/13100745.html
Copyright © 2020-2023  润新知