Объединение полей отчета

Добрый день! Подскажите, есть ли возможность при формировании отчета объединять одинаковые значения полей “Сотрудник” и “Проект” (в данном случае должно быть объединено поле admin и тестовый проект). Как на втором скриншоте

Новый точечный рисунок

2

1 симпатия

Доброе утро, Сергей.
Объединить одинаковые значения полей в таком виде не получится.

есть способы, которыми это можно сделать?

Сергей, возможный способ решения данной проблемы, это создание отчета с использованием https://doc.cuba-platform.com/reporting-6.2-ru/template_custom.html . В данном классе вы сможете сделать собственное форматирование данных, и объединить необходимые данные в группы. В качестве примера класс, который печатает xls. Отчет состоит из заголовка и двух строк данных. Строки объединены по колонкам Employee и Project (проект и отчет приложены к ответу):


public class EmployeeReport implements CustomReport {
    @Override
    public byte[] createReport(Report report, BandData rootBand, Map<String, Object> params) {
        HSSFWorkbook workbook = new HSSFWorkbook();
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        try {
            Sheet sheet = workbook.createSheet("EmployeeSheet");
            initHeaders(sheet);
            writeData(rootBand, sheet);
            workbook.write(outputStream);
        } catch (IOException e) {
            throw new RuntimeException("Unable to create xls", e);
        } finally {
            try {
                workbook.close();
            } catch (IOException e) {
                /*Do nothing*/
            }
        }
        return outputStream.toByteArray();
    }

    protected void initHeaders(Sheet sheet) {
        Row row = sheet.createRow(0);
        Cell cell = row.createCell(0);
        cell.setCellValue("Employee");

        cell = row.createCell(1);
        cell.setCellValue("Project");

        cell = row.createCell(2);
        cell.setCellValue("Work type");

        cell = row.createCell(3);
        cell.setCellValue("Hours");
    }

    protected void writeData(BandData rootBand, Sheet sheet) {
        int i = 1;
        for (BandData employee : rootBand.getChildrenByName("Employees")) {
            Row row = sheet.createRow(i);
            row.createCell(0).setCellValue((String) employee.getParameterValue("employee"));
            row.createCell(1).setCellValue((String) employee.getParameterValue("project"));
            row.createCell(2).setCellValue((String) employee.getParameterValue("workType"));
            row.createCell(3).setCellValue((Integer) employee.getParameterValue("hours"));
            i++;
        }
        /*create merged cells for employee column*/
        sheet.addMergedRegion(new CellRangeAddress(1, 2, 0, 0));
        /*create merged cells for project column*/
        sheet.addMergedRegion(new CellRangeAddress(1, 2, 1, 1));
    }
}

EmployeeReport.zip (25.5K)

Report - EmployeeReport.zip (2.6K)