Как предотвратить слияние столбцов ColumnBuilder для правильной работы?

Я пытаюсь сгенерировать файл xlsx из моего кода Java. Я использую Grails-Groovy здесь. Но некоторые свойства всегда состоят из двух или более объединенных столбцов.

Сгенерированный xlsx результат:

Сгенерированный результат xlsx

Свойство "старая персистентность" и "API" было создано путем объединения столбцов F&G и H&I в результате вывода

Это мой код:

import org.grails.web.json.JSONObject
import ar.com.fdvs.dj.domain.CustomExpression
import ar.com.fdvs.dj.core.DynamicJasperHelper
import ar.com.fdvs.dj.core.layout.ClassicLayoutManager
import ar.com.fdvs.dj.domain.AutoText
import ar.com.fdvs.dj.domain.DynamicReport
import ar.com.fdvs.dj.domain.Style
import ar.com.fdvs.dj.domain.builders.ColumnBuilder
import ar.com.fdvs.dj.domain.builders.DynamicReportBuilder
import ar.com.fdvs.dj.domain.constants.Border
import ar.com.fdvs.dj.domain.constants.Page
import ar.com.fdvs.dj.domain.constants.Font
import ar.com.fdvs.dj.domain.constants.HorizontalAlign
import ar.com.fdvs.dj.domain.constants.Transparency
import ar.com.fdvs.dj.domain.entities.columns.AbstractColumn
import net.sf.jasperreports.engine.JasperExportManager
import net.sf.jasperreports.engine.JasperFillManager
import net.sf.jasperreports.engine.JasperPrint
import net.sf.jasperreports.engine.JasperReport
import net.sf.jasperreports.engine.data.JRMapCollectionDataSource
import java.awt.*
import java.text.SimpleDateFormat
import net.sf.jasperreports.engine.export.ooxml.JRXlsxExporter
import net.sf.jasperreports.export.SimpleXlsxReportConfiguration
import net.sf.jasperreports.export.SimpleExporterInput
import net.sf.jasperreports.export.SimpleOutputStreamExporterOutput
import java.io.ByteArrayOutputStream

class ReportController {

final String DATE_FORMAT = "yyyy-MM-dd"
static responseFormats = ['json']
final String DATE_FORMAT = "yyyy-MM-dd"
static responseFormats = ['json']

def createDynamicReport() {
    Map<String, String> reportParam = new HashMap<>();
    reportParam.put(net.sf.jasperreports.engine.JRParameter.IS_IGNORE_PAGINATION, Boolean.TRUE);
    JSONObject jsonObject = request.JSON

    Style detailStyle = new Style();
    detailStyle.setBorder(Border.THIN())
    Style headerStyle = new Style();
    headerStyle.setBackgroundColor(new Color(80, 80, 80));
    headerStyle.setTextColor(Color.white);
    headerStyle.setBorder(Border.THIN())
    headerStyle.setHorizontalAlign(HorizontalAlign.CENTER);
    headerStyle.setTransparency(Transparency.OPAQUE);

    Style titleStyle = new Style();
    titleStyle.setFont(new Font(25, Font._FONT_ARIAL, false, false, false));
    titleStyle.setHorizontalAlign(HorizontalAlign.CENTER);
    Style subtitleStyle = new Style();
    Style amountStyle = new Style();
    amountStyle.setHorizontalAlign(HorizontalAlign.RIGHT);
    amountStyle.setBorder(Border.THIN())
    amountStyle.setTextColor(new Color(255, 0, 0));

    DynamicReportBuilder drb = new DynamicReportBuilder();
    drb.setTitle(jsonObject.title)
            .setSubtitle("Period: ${jsonObject.startDate} - ${jsonObject.endDate}")
            .setDetailHeight(15)
            .setMargins(30, 20, 30, 15)
            .setDefaultStyles(titleStyle, subtitleStyle, headerStyle, detailStyle)
            .setPrintBackgroundOnOddRows(true)
            .setColumnsPerPage(1);

    for (int i = 0; i < jsonObject.columns.size(); i++) {
        AbstractColumn column = ColumnBuilder.getNew()
            .setColumnProperty(jsonObject.columns[i].property, jsonObject.columns[i].type)
            .setTitle(jsonObject.columns[i].title)
            .setWidth(jsonObject.columns[i].width)
            .setFixedWidth(false)
        .build();
        drb.addColumn(column);
    }
    drb.setUseFullPageWidth(false);
    drb.setIgnorePagination(true);
    drb.addAutoText(AutoText.AUTOTEXT_PAGE_X_OF_Y, AutoText.POSITION_FOOTER, AutoText.ALIGNMENT_RIGHT);

    DynamicReport dr = drb.build();
    JasperReport jr = DynamicJasperHelper.generateJasperReport(dr, new ClassicLayoutManager(), reportParam);
    JasperPrint jp = JasperFillManager.fillReport(jr, reportParam, new JRMapCollectionDataSource(jsonObject.value));

    JRXlsxExporter exporter = new JRXlsxExporter();
    exporter.setExporterInput(new SimpleExporterInput(jp));
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(out));
    SimpleXlsxReportConfiguration configuration = new SimpleXlsxReportConfiguration(); 
    configuration.setDetectCellType(true);//Set configuration as you like it!!
    //configuration.setFitHeight(400)
    configuration.isCollapseRowSpan();
    configuration.setCollapseRowSpan(true);
    exporter.setConfiguration(configuration);
    exporter.exportReport();
    byte[] b = out.toByteArray();

    response.contentType = 'application/octet-stream'
    response.setHeader 'Content-disposition', 'Attachment;Filename=' + jsonObject.excelFileName
    response.outputStream << b
    response.outputStream.flush()
    return response
}}

и это объект JSON из request.JSON

{
            "excelFileName": "TEST BOSS",
            "title"        : "TEST BOSS",
            "startDate"    : "2017-01-01",
            "endDate"      : "2017-01-01",
            "columns"      : [
                        {"property": "agentNumber",         "type": "java.lang.String","title": "Agent Number","width": 100},
                        {"property": "leaderNumber",        "type": "java.lang.String","title": "Leader/Reff Number","width": 100},
                        {"property": "type",                "type": "java.lang.String","title": "Type","width": 40},                                                       
                        {"property": "rollingPersistency",  "type": "java.lang.Double","title": "Rolling Persistency","width": 100},
                        {"property": "persistency",         "type": "java.lang.Double","title": "Old Persistency","width": 100},
                        {"property": "api",                 "type": "java.lang.Double","title": "API","width": 100}
                    ],
            "value"        : [
                {"rollingPersistency":0.0, "api":781654242.07, "leaderNumber":"00003303", "type":"U", "agentNumber":"00045327", "persistency":0.0, "batchDate":0.0},
                {"rollingPersistency":0.0, "api":757672972.79, "leaderNumber":"00391726", "type":"U", "agentNumber":"00568307", "persistency":0.0, "batchDate":0.0}
                ]
}

Спасибо большое, ребята. Я надеюсь, что объяснил свою проблему достаточно ясно.

0 ответов

Другие вопросы по тегам