SpringBoot整合锐浪报表

一、前言

锐浪报表Grid++Report在报表工具中拥有最多开发者,支持主流编程语言,同时支持C/S报表与WEB报表的开发,WEB报表既有报表插件方式,也有跨平台的HTML5报表,为软件开发者提供最全面最高效的报表工具

二、搭建开发环境

test.png

2.1、window安装

test.png

2.1、linux安装

test.png

三、SpringBoot整合锐浪报表

3.1、pom.xml

test.png

        <!--引入GridReport依赖-->
        <dependency>
            <groupId>gridreport</groupId>
            <artifactId>gridreport</artifactId>
            <version>6.8</version>
            <scope>system</scope>
            <systemPath>${basedir}/src/main/resources/lib/gridreport.jar</systemPath>
        </dependency>

3.2、封装报表工具类

    /**
     *
     * @param templateStr 报表模板字符串
     * @param xmlData 数据库组装xml数据
     * @param type 导出类型
     * @throws Exception
     */
    public static BinaryObject DoExport(String configModulePath,String templateStr, String xmlData, ExportType type) throws Exception {
        Report.ConfigModulePath(configModulePath);
        Report report = new Report();
        Boolean success = report.LoadFromStr(templateStr);
        //目标组装数据
        success = report.LoadDataFromXML(xmlData);
        BinaryObject bo = report.ExportDirectToBinaryObject(type);
        return bo;
    }

3.3、实际应用

        //模板数据获取
        String templateStr = sysDicts.get(0).getFileTemplate().toString();
        Map<String, String> ojbMap = new HashMap<>();
        ojbMap.put("createTime", workPoJo1.getCreateTime().toString().substring(0, 10));
        ojbMap.put("content", workPoJo1.getContent().toString());
        ojbMap.put("creator", workPoJo1.getCreator().toString());
        Map<String,Object> map =new HashMap<>();
        map.put("row",ojbMap);
        String xmlString =XmlUtil.mapToXmlStr(map);
        xmlString=xmlString.substring(54,xmlString.length());
        String configModulePath = "";
        if(active.equals("prod")){
             configModulePath = SysConfigXmlUtil.getSysParamsByName("configModulePathLinux").toString();
        }else {
             configModulePath = SysConfigXmlUtil.getSysParamsByName("configModulePathWin").toString();
        }
        BinaryObject binaryObject = GridReportUtils.DoExport(configModulePath,templateStr, xmlString, ExportType.PDF);
        byte[] decodedBytes = binaryObject.getDataBuf();
        String base64String = "data:application/pdf;base64," +Base64.getEncoder().encodeToString(decodedBytes);

3.4、调用结果

test.png

posted on 2026-08-10 15:38  爱河  阅读(2)  评论(0)    收藏  举报

导航