java FREEMARKER属性以及踩坑

ss:LineStyle	线型,单元格边框样式
ss:Position	上下左右的位置
AlignMent   	对齐属性
   ss:HoriZontal:水平
   ss:VerTical:垂直
   ss:WrapText:自动换行
Column		列
Row			行
Cell			单元格
合并属性	        MerGeDown:向下合并
   MerGeAcross:向右合并
ss:FontName	字体样式
ss:Size		字体大小

【freemarker官网】
https://freemarker.apache.org/docs/ref_directive_if.html#ref.directive.if

<#list list as builder>
</#list>
<#if tongTiaoJianJiHe?size gt 18 >
</#if>
<#if (xuhao_index+1>18 && xuhao_index+1<=27)>
</#if>

【freemark判断是否为空】
${baiban.earlyWorkHour?if_exists}

ss:ExpandedRowCount=“3” 不删除EXCEL打不开

在这里插入图片描述

word动态表格利用freemarker导出  如果是矢量图,需要添加图片库,图片ID
然后调图片ID
因为失误,造成了是矢量图,应该是更简单的图片
【freemarker导出】
{
        // 文件夹地址
        String dirPrefix = RuoYiConfig.getProfile() + "/excel/";
        // 创建文件夹
        File path = new File(dirPrefix);
        if (!path.exists()) {
            path.mkdirs();
        }
        Map<String, Object> dataMap = new HashMap<>();
//        dataMap.put("list", list);
        try {
            // 模板文件所在路径
            Configuration configuration = new Configuration(Configuration.VERSION_2_3_28);
            configuration.setDefaultEncoding("UTF-8");
            //framemaker.ftl为要装载的模板
            configuration.setDirectoryForTemplateLoading(path);
            // 获取模板文件
            Template t = configuration.getTemplate("dangyuan.ftl");
            // 导出文件
//            SimpleDateFormat year = new SimpleDateFormat("yyyy-");
//            SimpleDateFormat month = new SimpleDateFormat("MM-");
//            SimpleDateFormat day = new SimpleDateFormat("dd");
//            String year1 = year.format(new Date());
//            String month1 = month.format(new Date());
//            String day1 = day.format(new Date());
//            String fileAddress = dirPrefix + year1 + month1 + day1 + "党支部打分详情表.xls";
            String fileAddress = dirPrefix + "党支部打分详情表.xls";
            // 文件地址
            File outFile = new File(fileAddress);
            Writer out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outFile), StandardCharsets.UTF_8));
            // 将填充数据填入模板文件并输出到目标文件
            t.process(dataMap, out);
            out.close();
            if (outFile.exists()) {
                // 构造一个读取文件的IO流对象
                InputStream ins = new FileInputStream(fileAddress);
                // 放到缓冲流里面
                BufferedInputStream bins = new BufferedInputStream(ins);
                // 获取文件输出IO流
                OutputStream outs = response.getOutputStream();
                BufferedOutputStream bouts = new BufferedOutputStream(outs);
                // 设置response内容的类型
                response.setContentType("application/x-download");
                // 设置文件大小
                response.setContentLength((int) outFile.length());
                // 设置头部信息
                response.setHeader("Content-disposition", "attachment;filename=" + URLEncoder.encode(outFile.getName(), "UTF-8"));
                int bytesRead = 0;
                byte[] buffer = new byte[8192];
                // 开始向网络传输文件流
                while ((bytesRead = bins.read(buffer, 0, 8192)) != -1) {
                    bouts.write(buffer, 0, bytesRead);
                }
                bouts.flush();// 这里一定要调用flush()方法
                ins.close();
                bins.close();
                outs.close();
                bouts.close();
                outFile.delete();
            } else {
                System.out.println("下载的文件不存在");
            }
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println(e.getMessage());
        }

    }
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值