Example usage for org.apache.poi.ss.usermodel Sheet addMergedRegion

List of usage examples for org.apache.poi.ss.usermodel Sheet addMergedRegion

Introduction

In this page you can find the example usage for org.apache.poi.ss.usermodel Sheet addMergedRegion.

Prototype

int addMergedRegion(CellRangeAddress region);

Source Link

Document

Adds a merged region of cells (hence those cells form one)

Usage

From source file:bad.robot.excel.row.CopyRow.java

License:Apache License

private static void copyMergeRegion(Sheet worksheet, Row sourceRow, Row newRow, CellRangeAddress mergedRegion) {
    CellRangeAddress range = mergedRegion;
    if (range.getFirstRow() == sourceRow.getRowNum()) {
        int lastRow = newRow.getRowNum() + (range.getFirstRow() - range.getLastRow());
        CellRangeAddress newCellRangeAddress = new CellRangeAddress(newRow.getRowNum(), lastRow,
                range.getFirstColumn(), range.getLastColumn());
        worksheet.addMergedRegion(newCellRangeAddress);
    }//from w w  w.jav  a 2 s .c  o m
}

From source file:bandaru_excelreadwrite.WritetoExcel.java

public void writeSongsListToExcel(List<Song> songList) {

    /*//from   w  ww . j a  v a  2  s .  c om
    Use XSSF for xlsx format and for xls use HSSF
     */
    Workbook workbook = new XSSFWorkbook();

    /*
    create new sheet 
     */
    Sheet songsSheet = workbook.createSheet("Albums");

    XSSFCellStyle my_style = (XSSFCellStyle) workbook.createCellStyle();
    /* Create XSSFFont object from the workbook */
    XSSFFont my_font = (XSSFFont) workbook.createFont();

    /*
    setting cell color
     */
    CellStyle style = workbook.createCellStyle();
    style.setFillForegroundColor(IndexedColors.LEMON_CHIFFON.getIndex());
    style.setFillPattern(CellStyle.SOLID_FOREGROUND);

    /*
     setting Header color
     */
    CellStyle style2 = workbook.createCellStyle();
    style2.setFillForegroundColor(IndexedColors.DARK_RED.getIndex());
    style2.setFillPattern(CellStyle.SOLID_FOREGROUND);
    style2.setAlignment(style2.ALIGN_CENTER);

    Row rowName = songsSheet.createRow(1);

    /*
    Merging the cells
     */
    songsSheet.addMergedRegion(new CellRangeAddress(1, 1, 2, 3));

    /*
    Applying style to attribute name
     */
    int nameCellIndex = 1;
    Cell namecell = rowName.createCell(nameCellIndex++);
    namecell.setCellValue("Name");
    namecell.setCellStyle(style);

    Cell cel = rowName.createCell(nameCellIndex++);
    cel.setCellValue("Bandaru, Sreekanth");

    /*
    Applying underline to Name
     */
    my_font.setUnderline(XSSFFont.U_SINGLE);
    my_style.setFont(my_font);
    /* Attaching the style to the cell */
    CellStyle combined = workbook.createCellStyle();
    combined.cloneStyleFrom(my_style);
    combined.cloneStyleFrom(style);
    combined.setAlignment(combined.ALIGN_CENTER);

    cel.setCellStyle(combined);

    /*
    Applying  colors to header 
     */
    Row rowMain = songsSheet.createRow(3);
    SheetConditionalFormatting sheetCF = songsSheet.getSheetConditionalFormatting();
    ConditionalFormattingRule rule1 = sheetCF.createConditionalFormattingRule("3");

    PatternFormatting fill1 = rule1.createPatternFormatting();
    fill1.setFillBackgroundColor(IndexedColors.LIME.index);
    fill1.setFillPattern(PatternFormatting.SOLID_FOREGROUND);

    CellRangeAddress[] regions = { CellRangeAddress.valueOf("A4:F4") };

    sheetCF.addConditionalFormatting(regions, rule1);

    /*
    setting new rule to apply alternate colors to cells having same Genre
     */
    ConditionalFormattingRule rule2 = sheetCF.createConditionalFormattingRule("4");
    PatternFormatting fill2 = rule2.createPatternFormatting();
    fill2.setFillBackgroundColor(IndexedColors.LEMON_CHIFFON.index);
    fill2.setFillPattern(PatternFormatting.SOLID_FOREGROUND);

    CellRangeAddress[] regionsAction = { CellRangeAddress.valueOf("A5:F5"), CellRangeAddress.valueOf("A6:F6"),
            CellRangeAddress.valueOf("A7:F7"), CellRangeAddress.valueOf("A8:F8"),
            CellRangeAddress.valueOf("A13:F13"), CellRangeAddress.valueOf("A14:F14"),
            CellRangeAddress.valueOf("A15:F15"), CellRangeAddress.valueOf("A16:F16"),
            CellRangeAddress.valueOf("A23:F23"), CellRangeAddress.valueOf("A24:F24"),
            CellRangeAddress.valueOf("A25:F25"), CellRangeAddress.valueOf("A26:F26")

    };

    /*        
    setting new rule to apply alternate colors to cells having same Fenre
     */
    ConditionalFormattingRule rule3 = sheetCF.createConditionalFormattingRule("4");
    PatternFormatting fill3 = rule3.createPatternFormatting();
    fill3.setFillBackgroundColor(IndexedColors.LIGHT_GREEN.index);
    fill3.setFillPattern(PatternFormatting.SOLID_FOREGROUND);

    CellRangeAddress[] regionsAdv = { CellRangeAddress.valueOf("A9:F9"), CellRangeAddress.valueOf("A10:F10"),
            CellRangeAddress.valueOf("A11:F11"), CellRangeAddress.valueOf("A12:F12"),
            CellRangeAddress.valueOf("A17:F17"), CellRangeAddress.valueOf("A18:F18"),
            CellRangeAddress.valueOf("A19:F19"), CellRangeAddress.valueOf("A20:F20"),
            CellRangeAddress.valueOf("A21:F21"), CellRangeAddress.valueOf("A22:F22"),
            CellRangeAddress.valueOf("A27:F27"), CellRangeAddress.valueOf("A28:F28"),
            CellRangeAddress.valueOf("A29:F29") };

    /*
    Applying above created rule formatting to cells
     */
    sheetCF.addConditionalFormatting(regionsAction, rule2);
    sheetCF.addConditionalFormatting(regionsAdv, rule3);

    /*
     Setting coloumn header values
     */
    int mainCellIndex = 0;
    CellStyle style4 = workbook.createCellStyle();
    XSSFFont my_font2 = (XSSFFont) workbook.createFont();
    my_font2.setBold(true);
    style4.setFont(my_font2);
    rowMain.setRowStyle(style4);
    rowMain.createCell(mainCellIndex++).setCellValue("SNO");
    rowMain.createCell(mainCellIndex++).setCellValue("Genre");
    rowMain.createCell(mainCellIndex++).setCellValue("Rating");
    rowMain.createCell(mainCellIndex++).setCellValue("Movie Name");
    rowMain.createCell(mainCellIndex++).setCellValue("Director");
    rowMain.createCell(mainCellIndex++).setCellValue("Release Date");

    /*
    populating cell values
     */
    int rowIndex = 4;
    int sno = 1;
    for (Song song : songList) {
        if (song.getSno() != 0) {

            Row row = songsSheet.createRow(rowIndex++);
            int cellIndex = 0;

            /*
            first place in row is Sno
             */
            row.createCell(cellIndex++).setCellValue(sno++);

            /*
            second place in row is  Genre
             */
            row.createCell(cellIndex++).setCellValue(song.getGenre());

            /*
            third place in row is Critic score
             */
            row.createCell(cellIndex++).setCellValue(song.getCriticscore());

            /*
            fourth place in row is Album name
             */
            row.createCell(cellIndex++).setCellValue(song.getAlbumname());

            /*
            fifth place in row is Artist
             */
            row.createCell(cellIndex++).setCellValue(song.getArtist());

            /*
            sixth place in row is marks in date
             */
            if (song.getReleasedate() != null) {

                Cell date = row.createCell(cellIndex++);

                DataFormat format = workbook.createDataFormat();
                CellStyle dateStyle = workbook.createCellStyle();

                dateStyle.setDataFormat(format.getFormat("dd-MMM-yyyy"));
                date.setCellStyle(dateStyle);

                date.setCellValue(song.getReleasedate());

                /*
                auto-resizing columns
                 */
                songsSheet.autoSizeColumn(6);
                songsSheet.autoSizeColumn(5);
                songsSheet.autoSizeColumn(4);
                songsSheet.autoSizeColumn(3);
                songsSheet.autoSizeColumn(2);
            }

        }
    }

    /*
    writing this workbook to excel file.
     */
    try {
        FileOutputStream fos = new FileOutputStream(FILE_PATH);
        workbook.write(fos);
        fos.close();

        System.out.println(FILE_PATH + " is successfully written");
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

}

From source file:br.com.algoritmo.compilacao.CompilaXlsx.java

License:Apache License

public static void main(String[] args) throws Exception {
    Workbook wb;/*w  ww.j ava 2 s .c om*/
    Map<Integer, Object[]> data = new TreeMap<Integer, Object[]>();
    data.put(0, new Object[] { 0, "Luiz Carlos Miyadaira Ribeiro Junior", "Base", "0468265522433921",
            "SOFTWARE", null, null, null });
    data.put(1, new Object[] { 1, "Sergio Antnio Andrade de Freitas", "Destino 1", "0395549254894676",
            "SOFTWARE", null, null, null });
    data.put(2, new Object[] { 2, "Andre Luiz Aquere de Cerqueira e Souza", "Destino 2", "8424412648258970",
            "CIVIL", null, null, null });
    data.put(3, new Object[] { 3, "Edson Mintsu Hung Destino", "Destino 3", "6753551743147880", "ELETRNICA",
            null, null, null });
    data.put(4, new Object[] { 4, "Edgard Costa Oliveira", "Destino 4", "1196380808351110", "SOFTWARE", null,
            null, null });
    data.put(5, new Object[] { 5, "Edson Alves da Costa Jnior", "Destino 5", "2105379147123450", "SOFTWARE",
            null, null, null });
    data.put(6, new Object[] { 6, "Andr Barros de Sales", "Destino 6", "7610669796869660", "SOFTWARE", null,
            null, null });
    data.put(7, new Object[] { 7, "Giovanni Almeida dos Santos", "Destino 7", "0580891429319047", "SOFTWARE",
            null, null, null });
    data.put(8, new Object[] { 8, "Cristiane Soares Ramos", "Destino 8", "9950213660160160", "SOFTWARE", null,
            null, null });
    data.put(9, new Object[] { 9, "Fabricio Ataides Braz", "Destino 9", "1700216932505000", "SOFTWARE", null,
            null, null });
    data.put(10, new Object[] { 10, "Alexandre Srgio de Arajo Bezerra", "Destino 10", "0255998976169051",
            "MEDICINA", null, null, null });
    data.put(11, new Object[] { 11, "Eduardo Stockler Tognetti", "Destino 11", "2443108673822680", "ELTRICA",
            null, null, null });
    data.put(12, new Object[] { 12, "Jan Mendona Correa", "Destino 12", "7844006017790570",
            "CINCIA DA COMPUTAO", null, null, null });
    data.put(13, new Object[] { 13, "Rejane Maria da Costa Figueiredo", "Destino 13", "2187680174312042",
            "SOFTWARE", null, null, null });
    data.put(14, new Object[] { 14, "Augusto Csar de Mendona Brasil", "Destino 14", "0571960641751286",
            "ENERGIA", null, null, null });
    data.put(15, new Object[] { 15, "Fbio Macdo Mendes", "Destino 15", "8075435338067780", "F?SICA", null,
            null, null });

    if (args.length > 0 && args[0].equals("-xls"))
        wb = new HSSFWorkbook();
    else
        wb = new XSSFWorkbook();

    Map<String, CellStyle> styles = createStyles(wb);

    Sheet aba1 = wb.createSheet("Percentual de similaridade 1");
    PrintSetup printSetup = aba1.getPrintSetup();
    printSetup.setLandscape(true);
    aba1.setFitToPage(true);
    aba1.setHorizontallyCenter(true);

    Sheet aba2 = wb.createSheet("Percentual de similaridade 2");
    PrintSetup printSetup2 = aba2.getPrintSetup();
    printSetup2.setLandscape(true);
    aba1.setFitToPage(true);
    aba1.setHorizontallyCenter(true);

    //title row
    Row titleRow = aba1.createRow(0);
    titleRow.setHeightInPoints(15);
    Cell titleCell = titleRow.createCell(0);
    titleCell.setCellValue(
            "Resultado da aplicao do algoritmo de clculo do percentual de similaridade entre os indivduos");
    titleCell.setCellStyle(styles.get("title"));
    aba1.addMergedRegion(CellRangeAddress.valueOf("$A$1:$H$1"));

    //header row
    Row headerRow = aba1.createRow(1);
    headerRow.setHeightInPoints(15);
    Cell headerCell;
    for (int i = 1; i <= titles.length; i++) {
        headerCell = headerRow.createCell(i);
        headerCell.setCellValue(titles[i - 1]);
        headerCell.setCellStyle(styles.get("header"));
    }

    Row headerBase = aba1.createRow(2);
    headerBase.setHeightInPoints(15);
    Cell headerCellBase;
    for (int i = 1; i <= base.length; i++) {
        headerCellBase = headerBase.createCell(i);
        headerCellBase.setCellValue(base[i - 1]);
        headerCellBase.setCellStyle(styles.get("header1"));
    }

    Row headerDestino = aba1.createRow(4);
    headerDestino.setHeightInPoints(15);
    Cell headerCellDestino;
    for (int i = 1; i <= destino.length; i++) {
        headerCellDestino = headerDestino.createCell(i);
        headerCellDestino.setCellValue(destino[i - 1]);
        headerCellDestino.setCellStyle(styles.get("header1"));
    }

    /*int rownum = 2;
    for (int i = 0; i < 10; i++) {
        Row row = sheet.createRow(rownum++);
        for (int j = 0; j < titles.length; j++) {
     Cell cell = row.createCell(j);
     if(j == 9){
         //the 10th cell contains sum over week days, e.g. SUM(C3:I3)
         String ref = "C" +rownum+ ":I" + rownum;
         cell.setCellFormula("SUM("+ref+")");
         cell.setCellStyle(styles.get("formula"));
     } else if (j == 11){
         cell.setCellFormula("J" +rownum+ "-K" + rownum);
         cell.setCellStyle(styles.get("formula"));
     } else {
         cell.setCellStyle(styles.get("cell"));
     }
        }
    }
            
    rownum = 3;
    for (int i = 0; i < 10; i++) {
        Row row = sheet.createRow(rownum++);
        for (int j = 0; j < titles1.length; j++) {
     Cell cell = row.createCell(j);
     if(j == 9){
         //the 10th cell contains sum over week days, e.g. SUM(C3:I3)
         String ref = "C" +rownum+ ":I" + rownum;
         cell.setCellFormula("SUM("+ref+")");
         cell.setCellStyle(styles.get("formula"));
     } else if (j == 11){
         cell.setCellFormula("J" +rownum+ "-K" + rownum);
         cell.setCellStyle(styles.get("formula"));
     } else {
         cell.setCellStyle(styles.get("cell"));
     }
        }
    }
    */
    //set sample data
    //Iterate over data and write to sheet
    Set<Integer> keyset = data.keySet();
    int rownum = 0;
    for (Integer key : keyset) {
        Row row = aba1.createRow(3 + rownum++);
        Object[] objArr = data.get(key);
        int cellnum = 0;
        for (Object obj : objArr) {
            Cell cell = row.createCell(cellnum++);
            if (obj instanceof String)
                cell.setCellValue((String) obj);
            else if (obj instanceof Integer)
                cell.setCellValue((Integer) obj);
        }
        if (row.getRowNum() == 3) {
            rownum++;
        }
    }
    //finally set column widths, the width is measured in units of 1/256th of a character width
    aba1.setColumnWidth(0, 2 * 256); //2 characters wide
    aba1.setColumnWidth(1, 26 * 256); //26 characters wide
    aba1.setColumnWidth(2, 20 * 256); //20 characters wide
    aba1.setColumnWidth(3, 18 * 256); //18 characters wide
    aba1.setColumnWidth(4, 20 * 256); //20 characters wide
    for (int i = 5; i < 9; i++) {
        aba1.setColumnWidth(i, 15 * 256); //6 characters wide
    }

    // Write the output to a file
    String file = "Sada/Percentual de similaridade.xls";
    if (wb instanceof XSSFWorkbook)
        file += "x";
    FileOutputStream out = new FileOutputStream(file);
    wb.write(out);
    out.close();
}

From source file:br.com.tecsinapse.dataio.util.WorkbookUtil.java

License:LGPL

public Workbook toWorkBook(Workbook wb, Table table) {
    List<List<TableCell>> matrix = table.getCells();
    List<List<TableCell>> matrixFull = table.toTableCellMatrix();

    replaceColorsPallete(table.getColorsReplaceMap(), wb);

    String sheetName = table.getTitle();
    Sheet sheet = sheetName == null ? wb.createSheet() : wb.createSheet(sheetName);
    int titleRows = 0;
    int r = titleRows;
    int c = 0;/*from w ww .  j  a  v a2  s .co m*/
    int maxColumns = -1;
    Map<Integer, Integer> defaultColumnWidth = new HashMap<>();

    ExporterFormatter tableExporterFormatter = table.getExporterFormatter();

    for (List<TableCell> row : matrix) {
        Row sheetRow = sheet.createRow(r);

        for (TableCell tableCell : row) {
            while (matrixFull.get(r - titleRows).get(c) == EmptyTableCell.EMPTY_CELL) {
                c++;
                if (c >= matrixFull.get(r - titleRows).size()) {
                    c = 0;
                    r++;
                }
            }

            Cell cell = sheetRow.createCell(c);
            if (c > maxColumns) {
                maxColumns = c;
            }

            if (tableCell.getRowspan() > 1 || tableCell.getColspan() > 1) {
                int rowStart = r;
                int rowEnd = rowStart + (tableCell.getRowspan() - 1);
                int colStart = c;
                int colEnd = colStart + (tableCell.getColspan() - 1);

                CellRangeAddress cellRange = new CellRangeAddress(rowStart, rowEnd, colStart, colEnd);
                sheet.addMergedRegion(cellRange);

                RegionUtil.setBorderTop(BorderStyle.THIN, cellRange, sheet);
                RegionUtil.setBorderRight(BorderStyle.THIN, cellRange, sheet);
                RegionUtil.setBorderBottom(BorderStyle.THIN, cellRange, sheet);
                RegionUtil.setBorderLeft(BorderStyle.THIN, cellRange, sheet);
            } else if (!table.isAutoSizeColumnSheet()) {
                Integer maxColumnWidth = defaultColumnWidth.get(c);
                if (maxColumnWidth == null) {
                    defaultColumnWidth.put(c, tableCell.getDefaultColumnWidth());
                } else {
                    int defaultWidth = tableCell.getDefaultColumnWidth();
                    if (defaultWidth > maxColumnWidth) {
                        defaultColumnWidth.put(c, defaultWidth);
                    }
                }
            }

            String format = setConvertedValue(cell, tableCell, tableExporterFormatter);
            setCellStyle(cell, tableCell, wb, format);
            c++;
        }
        r++;
        c = 0;
    }

    if (table.isAutoSizeColumnSheet()) {
        for (int i = 0; i <= maxColumns; ++i) {
            if (sheet instanceof SXSSFSheet) {
                ((SXSSFSheet) sheet).trackColumnForAutoSizing(i);
            }
            sheet.autoSizeColumn(i, true);
        }
    } else {
        for (int i = 0; i <= maxColumns; ++i) {
            if (defaultColumnWidth.get(i) == null) {
                if (sheet instanceof SXSSFSheet) {
                    ((SXSSFSheet) sheet).trackColumnForAutoSizing(i);
                }
                sheet.autoSizeColumn(i, true);
            } else {
                int width = table.getMinOrMaxOrActualCellWidth(defaultColumnWidth.get(i));
                sheet.setColumnWidth(i, width);
            }
        }
    }
    return wb;
}

From source file:br.com.tecsinapse.exporter.util.WorkbookUtil.java

License:LGPL

public Workbook toWorkBook(Workbook wb, Table table) {
    List<List<TableCell>> matrix = table.getCells();
    List<List<TableCell>> matrixFull = table.toTableCellMatrix();

    String sheetName = table.getTitle();
    Sheet sheet = sheetName == null ? wb.createSheet() : wb.createSheet(sheetName);
    int titleRows = 0;
    int r = titleRows;
    int c = 0;/*w w  w  .  j av  a 2 s .c  om*/
    int maxColumns = -1;
    Map<Integer, Integer> defaultColumnWidth = new HashMap<>();

    ExporterFormatter tableExporterFormatter = table.getExporterFormatter();

    for (List<TableCell> row : matrix) {
        Row sheetRow = sheet.createRow(r);

        for (TableCell tableCell : row) {
            while (matrixFull.get(r - titleRows).get(c) == EmptyTableCell.EMPTY_CELL) {
                c++;
                if (c >= matrixFull.get(r - titleRows).size()) {
                    c = 0;
                    r++;
                }
            }

            Cell cell = sheetRow.createCell(c);
            if (c > maxColumns) {
                maxColumns = c;
            }

            if (tableCell.getRowspan() > 1 || tableCell.getColspan() > 1) {
                int rowStart = r;
                int rowEnd = rowStart + (tableCell.getRowspan() - 1);
                int colStart = c;
                int colEnd = colStart + (tableCell.getColspan() - 1);

                CellRangeAddress cellRange = new CellRangeAddress(rowStart, rowEnd, colStart, colEnd);
                sheet.addMergedRegion(cellRange);

                RegionUtil.setBorderTop(1, cellRange, sheet, wb);
                RegionUtil.setBorderRight(1, cellRange, sheet, wb);
                RegionUtil.setBorderBottom(1, cellRange, sheet, wb);
                RegionUtil.setBorderLeft(1, cellRange, sheet, wb);
            } else if (!table.isAutoSizeColumnSheet()) {
                Integer maxColumnWidth = defaultColumnWidth.get(c);
                if (maxColumnWidth == null) {
                    defaultColumnWidth.put(c, tableCell.getDefaultColumnWidth());
                } else {
                    int defaultWidth = tableCell.getDefaultColumnWidth();
                    if (defaultWidth > maxColumnWidth) {
                        defaultColumnWidth.put(c, defaultWidth);
                    }
                }
            }

            String format = setConvertedValue(cell, tableCell, tableExporterFormatter);
            setCellStyle(cell, tableCell, wb, format);
            c++;
        }
        r++;
        c = 0;
    }

    if (table.isAutoSizeColumnSheet()) {
        for (int i = 0; i <= maxColumns; ++i) {
            if (sheet instanceof SXSSFSheet) {
                ((SXSSFSheet) sheet).trackColumnForAutoSizing(i);
            } else {
                sheet.autoSizeColumn(i, true);
            }
        }
    } else {
        for (int i = 0; i <= maxColumns; ++i) {
            if (defaultColumnWidth.get(i) == null) {
                if (sheet instanceof SXSSFSheet) {
                    ((SXSSFSheet) sheet).trackColumnForAutoSizing(i);
                } else {
                    sheet.autoSizeColumn(i, true);
                }
            } else {
                sheet.setColumnWidth(i, defaultColumnWidth.get(i));
            }
        }
    }
    return wb;
}

From source file:br.ufpa.psi.comportamente.labgame.relatorios.RelatorioJogadasExperimento.java

License:Open Source License

public InputStream relatorioOntogenese(Long idExp) throws FileNotFoundException, IOException {
    Workbook wb = new XSSFWorkbook();
    Sheet sheet = wb.createSheet("Relatrio Ontognese");

    JogadaDAO jogadaDAO = new JogadaDAO();

    jogadaDAO.beginTransaction();//from w  ww  .ja  v  a  2s  .  co m
    List<Jogada> jogadasAux = jogadaDAO.encontrarPorExperimento(idExp);
    jogadaDAO.stopOperation(false);

    ExperimentoDAO expDAO = new ExperimentoDAO();

    expDAO.beginTransaction();
    Experimento experimento = expDAO.find(Experimento.class, idExp);
    expDAO.stopOperation(false);

    JogadorDAO jogDAO = new JogadorDAO();

    jogDAO.beginTransaction();
    List<Jogador> jogadoresTotais = jogDAO.encontraPorExperimento(experimento);
    jogDAO.stopOperation(false);

    //CRIA O CABEALHO "ONTOGNESE
    int quantidadeColunas = 6;
    int quantidadeJogadoresPorCiclo = experimento.getTamanhoFilaJogadores(); //Vai pegar o valor de acordo com o experimento.
    int larguraColuna = 4600;
    int colunaAtual;
    int colunaFinalOntogenese = (quantidadeColunas * quantidadeJogadoresPorCiclo) + 1;

    // --- DEFINE AS PROPRIEDADES DAS CLULAS
    sheet.addMergedRegion(new CellRangeAddress(0, 2, 0, 0));
    sheet.addMergedRegion(new CellRangeAddress(0, 2, 1, 1));
    sheet.setColumnWidth(0, 1500);
    sheet.setColumnWidth(1, 2000);
    sheet.addMergedRegion(new CellRangeAddress(0, 1, 2, colunaFinalOntogenese));
    sheet.addMergedRegion(new CellRangeAddress(1, 2, colunaFinalOntogenese + 1, colunaFinalOntogenese + 1));
    sheet.setColumnWidth(colunaFinalOntogenese + 1, 3000);
    sheet.addMergedRegion(new CellRangeAddress(1, 3, colunaFinalOntogenese + 2, colunaFinalOntogenese + 2));
    sheet.setColumnWidth(colunaFinalOntogenese + 2, 4000);

    // --- FIM

    //for (int i = 0; i < quantidadeJogadoresPorCiclo; i++)
    //if(i == 1){
    sheet.setColumnWidth(2, larguraColuna); // Campo com o nome do participante fica nessa coluna.
    colunaAtual = 2 + quantidadeColunas;
    //} else {
    sheet.setColumnWidth((colunaAtual), larguraColuna);
    colunaAtual += quantidadeColunas;
    sheet.setColumnWidth(colunaAtual, larguraColuna);

    //}
    // ---DEFINE AS CORES DE CADA FONTE
    XSSFFont fonteBranca = (XSSFFont) wb.createFont();
    fonteBranca.setColor(new XSSFColor(Color.WHITE));
    XSSFFont fonteNegra = (XSSFFont) wb.createFont();
    fonteNegra.setColor(new XSSFColor(Color.BLACK));
    XSSFFont fonteVermelha = (XSSFFont) wb.createFont();
    fonteVermelha.setColor(new XSSFColor(Color.RED));

    // --- FIM

    // --- DEFINE ESTILOS CLULAS
    //ESTILO COLUNA LINHA
    XSSFCellStyle estiloColunaLinha = (XSSFCellStyle) wb.createCellStyle();

    estiloColunaLinha.setVerticalAlignment(VerticalAlignment.CENTER);
    estiloColunaLinha.setAlignment(CellStyle.ALIGN_CENTER);
    estiloColunaLinha.setFillForegroundColor(new XSSFColor(Color.LIGHT_GRAY));
    estiloColunaLinha.setFillPattern(CellStyle.SOLID_FOREGROUND);
    estiloColunaLinha.getFont().setBold(true);
    estiloColunaLinha.setBorderBottom(BorderStyle.MEDIUM);
    estiloColunaLinha.setBorderLeft(BorderStyle.MEDIUM);
    estiloColunaLinha.setBorderRight(BorderStyle.MEDIUM);
    estiloColunaLinha.setBorderTop(BorderStyle.MEDIUM);

    XSSFCellStyle estiloColunaColuna = (XSSFCellStyle) wb.createCellStyle();

    estiloColunaColuna.setVerticalAlignment(VerticalAlignment.CENTER);
    estiloColunaColuna.setAlignment(CellStyle.ALIGN_CENTER);
    estiloColunaColuna.getFont().setBold(true);

    //ESTILO CABEALHO
    XSSFCellStyle estiloCabecalhoColunaAB = (XSSFCellStyle) wb.createCellStyle();

    estiloCabecalhoColunaAB.setVerticalAlignment(VerticalAlignment.CENTER);
    estiloCabecalhoColunaAB.setAlignment(CellStyle.ALIGN_CENTER);
    estiloCabecalhoColunaAB.setFillForegroundColor(new XSSFColor(Color.LIGHT_GRAY));
    estiloCabecalhoColunaAB.setFillPattern(CellStyle.SOLID_FOREGROUND);
    estiloCabecalhoColunaAB.getFont().setBold(true);

    XSSFCellStyle estiloCabecalhoColunaP = (XSSFCellStyle) wb.createCellStyle();

    estiloCabecalhoColunaP.setVerticalAlignment(VerticalAlignment.CENTER);
    estiloCabecalhoColunaP.setAlignment(CellStyle.ALIGN_CENTER);
    estiloCabecalhoColunaP.setFont(fonteNegra);
    estiloCabecalhoColunaP.getFont().setBold(true);

    //ESTILO MUDANA DE CICLO
    XSSFCellStyle estiloMudancaCiclo = (XSSFCellStyle) wb.createCellStyle();
    estiloMudancaCiclo.setVerticalAlignment(VerticalAlignment.CENTER);
    estiloMudancaCiclo.setAlignment(CellStyle.ALIGN_CENTER);
    estiloMudancaCiclo.setFillForegroundColor(new XSSFColor(Color.RED));
    estiloMudancaCiclo.setFillPattern(CellStyle.SOLID_FOREGROUND);
    estiloMudancaCiclo.setFont(fonteBranca);

    //ESTILO CICLO SEM MUDANA
    XSSFCellStyle estiloCicloSemMudanca = (XSSFCellStyle) wb.createCellStyle();
    estiloCicloSemMudanca.setVerticalAlignment(VerticalAlignment.CENTER);
    estiloCicloSemMudanca.setAlignment(CellStyle.ALIGN_CENTER);
    estiloCicloSemMudanca.setFont(fonteNegra);

    //ESTILO NOME PARTICIPANTE
    XSSFCellStyle estiloNomeP = (XSSFCellStyle) wb.createCellStyle();
    estiloNomeP.setVerticalAlignment(VerticalAlignment.CENTER);
    estiloNomeP.setAlignment(CellStyle.ALIGN_CENTER);
    estiloNomeP.setBorderBottom(BorderStyle.DOTTED);
    estiloNomeP.setBorderTop(BorderStyle.DOTTED);
    estiloNomeP.setFillForegroundColor(new XSSFColor(Color.BLACK));
    estiloNomeP.setFillPattern(CellStyle.SOLID_FOREGROUND);
    estiloNomeP.setFont(fonteBranca);
    estiloNomeP.getFont().setBold(true);

    //ESTILO ESTABILIDADE
    XSSFCellStyle estiloEstabilidade = (XSSFCellStyle) wb.createCellStyle();
    estiloEstabilidade.setVerticalAlignment(VerticalAlignment.CENTER);
    estiloEstabilidade.setAlignment(CellStyle.ALIGN_CENTER);
    estiloEstabilidade.setFont(fonteVermelha);
    estiloEstabilidade.getFont().setBold(true);

    // --- FIM

    int cr = 0;

    // --- CRIA PRIMEIRA COLUNA (CABEALHO)
    XSSFRow row1 = (XSSFRow) sheet.createRow((short) cr++);

    //CRIA CLULA 1
    XSSFCell c1 = row1.createCell(0);

    c1.setCellValue("FASE");
    c1.setCellStyle(estiloCabecalhoColunaAB);

    //CRIA CLULA 2
    XSSFCell c2 = row1.createCell(1);

    c2.setCellValue("CICLO");
    c2.setCellStyle(estiloCabecalhoColunaAB);

    //CRIA CLULA 3 (ONTOGNESE)
    XSSFCell cOnto = row1.createCell(2);
    cOnto.setCellValue("ONTOGNESE");
    cOnto.setCellStyle(estiloCicloSemMudanca);

    //CRIA CLULA 'CC'
    XSSFRow row2 = (XSSFRow) sheet.createRow(1);
    XSSFCell cCC = row2.createCell(colunaFinalOntogenese + 1);
    cCC.setCellValue("CC");
    cCC.setCellStyle(estiloCicloSemMudanca);

    //CRIA CLULA 'ESTABILIDADE'
    XSSFCell cEstab = row2.createCell(colunaFinalOntogenese + 2);
    cEstab.setCellValue("ESTABILIDADE");
    cEstab.setCellStyle(estiloEstabilidade);

    // --- FIM

    int contadorCelulasCabecalho = 2;
    int contadorAcertosCultural = 0;
    XSSFRow row3 = (XSSFRow) sheet.createRow((short) 2);
    //GERA O CABEALHO DAS JOGADAS
    for (int i = 0; i < experimento.getTamanhoFilaJogadores(); i++) {
        //CRIA CLULA 3 NA LINHA 3
        XSSFCell c3 = row3.createCell(contadorCelulasCabecalho++);

        c3.setCellValue("P");
        c3.setCellStyle(estiloCabecalhoColunaP);

        //CRIA CLULA 4 NA LINHA 3
        XSSFCell c4 = row3.createCell(contadorCelulasCabecalho++);

        c4.setCellValue("Linha");
        c4.setCellStyle(estiloCabecalhoColunaP);

        //CRIA CLULA 5 NA LINHA 3
        XSSFCell c5 = row3.createCell(contadorCelulasCabecalho++);

        c5.setCellValue("Cor");
        c5.setCellStyle(estiloCabecalhoColunaP);

        //CRIA CLULA 6 NA LINHA 3
        XSSFCell c6 = row3.createCell(contadorCelulasCabecalho++);

        c6.setCellValue("Col");
        c6.setCellStyle(estiloCabecalhoColunaP);

        //CRIA CLULA 7 NA LINHA 3
        XSSFCell c7 = row3.createCell(contadorCelulasCabecalho++);

        c7.setCellValue("CI");
        c7.setCellStyle(estiloCabecalhoColunaP);

        //CRIA CLULA 8 NA LINHA 3
        XSSFCell c8 = row3.createCell(contadorCelulasCabecalho++);

        c8.setCellValue("CI Cum");
        c8.setCellStyle(estiloCabecalhoColunaP);

    }

    //VARI?VEIS INICIAIS DA ELABORAO DO RELATRIO
    int quantidadeCiclosTotais = (jogadasAux.size() / experimento.getTamanhoFilaJogadores());
    int contRowJogadas = 4;
    int contadorCiclo = 1;

    //INICIA LISTA DOS JOGADORES POR ORDEM
    List<Jogador> jogadoresAtuais = new ArrayList<>();
    int contOrdem = 1;
    for (int i = 0; i < quantidadeJogadoresPorCiclo; i++) {
        for (Jogador jgdr : jogadoresTotais) {
            if (jgdr.getOrdem() == contOrdem) {
                jogadoresAtuais.add(jgdr);
                contOrdem++;
                break;
            }
        }
    }

    //FAZ A REMOO DO(S) ELEMENTO(S) DA LISTA PRA POUPAR RECURSO EM BUSCA FUTURA
    jogadoresTotais.removeAll(jogadoresAtuais);

    //CRIA INSTNCIA CONTROLE DE PONTUAO CULTURAL
    int pontCulturalCiclo;

    //FOR (JOGADOR : JOGADORES POR CICLO)
    //CRIA LISTA DE CADA JOGADOR AT FIM DO CICLO
    for (int i = 0; i < quantidadeCiclosTotais; i++) {
        //PEGA JOGADAS DO CICLO
        List<Jogada> jogadasCiclo = new ArrayList<>();
        for (Jogada jogada : jogadasAux) {
            if (jogada.getRodada() == i + 1) {
                jogadasCiclo.add(jogada);
                if (jogadasCiclo.size() == quantidadeJogadoresPorCiclo) {
                    break;
                }
            }
        }
        //FAZ A REMOO DO(S) ELEMENTO(S) DA LISTA PRA POUPAR RECURSO EM BUSCA FUTURA
        jogadasAux.removeAll(jogadasCiclo);

        //VERIFICA SE A ORDEM MUDOU
        int contJogadoresIguais = 0;
        List<Jogada> jogadasARemover = new ArrayList<>();
        for (Jogador jogador : jogadoresAtuais) {
            for (Jogada jogada : jogadasCiclo) {
                if (jogada.getJogador().compareTo(jogador) == 0) {
                    jogador.setUltimaJogada(jogada);
                    jogador.incrementaPontuacaoRelatorio();
                    jogadasARemover.add(jogada);
                    contJogadoresIguais++;
                }
            }
        }

        jogadasCiclo.removeAll(jogadasARemover);

        boolean mudouGeracaoCiclo = false;
        if (contJogadoresIguais == quantidadeJogadoresPorCiclo) {
            //CONTINUA COM OS MESMOS JOGADORES
        } else {
            mudouGeracaoCiclo = true;
            Jogador jogadorARemover = new Jogador();
            jogadoresAtuais.remove(0);
            for (Jogador jgdr : jogadoresTotais) {
                if (jgdr.getOrdem() == contOrdem) {
                    //PEGA A PRIMEIRA POSIO PQ ESSA TEM QUE SER A NICA COM ELEMENTO
                    jgdr.setUltimaJogada(jogadasCiclo.get(0));
                    jgdr.incrementaPontuacaoRelatorio();
                    jogadoresAtuais.add(jgdr);
                    contOrdem++;
                    jogadorARemover = jgdr;
                    break;
                }
            }
            jogadoresTotais.remove(jogadorARemover);
        }
        // --- ENCERRA ETAPAS DE VERIFICAO, INICIA A POPULAO DE NOVA LINHA DO XLSX E
        //VERIFICA SE EXISTE PONTUAO CULTURAL.
        int contCellJogadas = 1;
        if (jogadoresAtuais.get(0).getUltimaJogada().getPontuacaoCultural() != 0) {
            pontCulturalCiclo = jogadoresAtuais.get(0).getUltimaJogada().getPontuacaoCultural();
            contadorAcertosCultural++;
        } else {
            pontCulturalCiclo = 0;
        }

        XSSFRow row = (XSSFRow) sheet.createRow((short) contRowJogadas);
        XSSFCell cell = row.createCell(contCellJogadas++);
        //CICLO
        if (contRowJogadas == 4 || mudouGeracaoCiclo == true) {
            //QUANDO HOUVER MUDANA DA GERAO
            cell.setCellValue(contadorCiclo++);
            cell.setCellStyle(estiloMudancaCiclo);
        } else {
            cell.setCellValue(contadorCiclo++);
            cell.setCellStyle(estiloCicloSemMudanca);
        }

        for (int j = 0; j < quantidadeJogadoresPorCiclo; j++) {

            //P
            XSSFCell cell1 = row.createCell(contCellJogadas++);
            cell1.setCellValue(jogadoresAtuais.get(j).getNome());
            cell1.setCellStyle(estiloNomeP);

            //Linha
            XSSFCell cell2 = row.createCell(contCellJogadas++);
            cell2.setCellValue(jogadoresAtuais.get(j).getUltimaJogada().getLinhaSelecionada());
            cell2.setCellStyle(estiloColunaLinha);

            //Cor
            XSSFCell cell3 = row.createCell(contCellJogadas++);
            cell3.setCellValue(jogadoresAtuais.get(j).getUltimaJogada().getCorSelecionada());
            cell3.setCellStyle(EstiloCelula.retornaEstilo(
                    jogadoresAtuais.get(j).getUltimaJogada().getCorSelecionada(), wb, fonteBranca, fonteNegra));

            //Col
            XSSFCell cell4 = row.createCell(contCellJogadas++);
            cell4.setCellValue(jogadoresAtuais.get(j).getUltimaJogada().getColunaSelecionada());
            cell4.setCellStyle(estiloColunaColuna);

            //CI
            XSSFCell cell5 = row.createCell(contCellJogadas++);
            cell5.setCellValue(jogadoresAtuais.get(j).getUltimaJogada().getPontuacaoIndividual());
            cell5.setCellStyle(estiloColunaColuna);

            //CI Cum
            XSSFCell cell6 = row.createCell(contCellJogadas++);
            cell6.setCellValue(jogadoresAtuais.get(j).getPontuacaoExibidaRelatorio());
            cell6.setCellStyle(estiloColunaColuna);
        }
        //CC
        XSSFCell cell7 = row.createCell(contCellJogadas++);
        cell7.setCellValue(pontCulturalCiclo);
        cell7.setCellStyle(estiloCabecalhoColunaAB);

        // ESTABILIDADE
        XSSFCell cell8 = row.createCell(contCellJogadas);
        cell8.setCellValue((contadorAcertosCultural * 100) / (i + 1) + "%");
        cell8.setCellStyle(estiloColunaColuna);

        contRowJogadas++;
    }

    //ESCREVE O ARQUIVO
    byte[] bytes;
    try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
        wb.write(out);
        bytes = out.toByteArray();
    }
    return new ByteArrayInputStream(bytes);
}

From source file:cn.afterturn.easypoi.excel.export.ExcelExportService.java

License:Apache License

/**
 * /*  w w w .ja  v a 2s. c o  m*/
 */
private int createHeaderRow(ExportParams title, Sheet sheet, Workbook workbook, int index,
        List<ExcelExportEntity> excelParams, int cellIndex) {
    Row row = sheet.getRow(index) == null ? sheet.createRow(index) : sheet.getRow(index);
    int rows = getRowNums(excelParams, true);
    row.setHeight(title.getHeaderHeight());
    Row listRow = null;
    if (rows >= 2) {
        listRow = sheet.createRow(index + 1);
        listRow.setHeight(title.getHeaderHeight());
    }
    int groupCellLength = 0;
    CellStyle titleStyle = getExcelExportStyler().getTitleStyle(title.getColor());
    for (int i = 0, exportFieldTitleSize = excelParams.size(); i < exportFieldTitleSize; i++) {
        ExcelExportEntity entity = excelParams.get(i);
        // ?groupName???
        if (StringUtils.isBlank(entity.getGroupName()) || i == 0
                || !entity.getGroupName().equals(excelParams.get(i - 1).getGroupName())) {
            if (groupCellLength > 1) {
                sheet.addMergedRegion(
                        new CellRangeAddress(index, index, cellIndex - groupCellLength, cellIndex - 1));
            }
            groupCellLength = 0;
        }
        if (StringUtils.isNotBlank(entity.getGroupName())) {
            createStringCell(row, cellIndex, entity.getGroupName(), titleStyle, entity);
            createStringCell(listRow, cellIndex, entity.getName(), titleStyle, entity);
            groupCellLength++;
        } else if (StringUtils.isNotBlank(entity.getName())) {
            createStringCell(row, cellIndex, entity.getName(), titleStyle, entity);
        }
        if (entity.getList() != null) {
            // ???
            int tempCellIndex = cellIndex;
            cellIndex = createHeaderRow(title, sheet, workbook, rows == 1 ? index : index + 1, entity.getList(),
                    cellIndex);
            List<ExcelExportEntity> sTitel = entity.getList();
            if (StringUtils.isNotBlank(entity.getName()) && sTitel.size() > 1) {
                PoiMergeCellUtil.addMergedRegion(sheet, index, index, tempCellIndex,
                        tempCellIndex + sTitel.size() - 1);
            }
            /*for (int j = 0, size = sTitel.size(); j < size; j++) {
                    
            createStringCell(rows == 2 ? listRow : row, cellIndex, sTitel.get(j).getName(),
                    titleStyle, entity);
            cellIndex++;
            }*/
            cellIndex--;
        } else if (rows > 1 && StringUtils.isBlank(entity.getGroupName())) {
            createStringCell(listRow, cellIndex, "", titleStyle, entity);
            PoiMergeCellUtil.addMergedRegion(sheet, index, index + rows - 1, cellIndex, cellIndex);
        }
        cellIndex++;
    }
    if (groupCellLength > 1) {
        PoiMergeCellUtil.addMergedRegion(sheet, index, index, cellIndex - groupCellLength, cellIndex - 1);
    }
    return cellIndex;

}

From source file:cn.bzvs.excel.export.base.ExcelExportBase.java

License:Apache License

/**
 *  ? Cells//from   w w  w .  j  ava  2  s  . c  o  m
 *
 * @param patriarch
 * @param index
 * @param t
 * @param excelParams
 * @param sheet
 * @param workbook
 * @param rowHeight
 * @return
 * @throws Exception
 */
public int createCells(Drawing patriarch, int index, Object t, List<ExcelExportEntity> excelParams, Sheet sheet,
        Workbook workbook, short rowHeight) throws Exception {
    ExcelExportEntity entity;
    Row row = sheet.createRow(index);
    row.setHeight(rowHeight);
    int maxHeight = 1, cellNum = 0;
    int indexKey = createIndexCell(row, index, excelParams.get(0));
    cellNum += indexKey;
    for (int k = indexKey, paramSize = excelParams.size(); k < paramSize; k++) {
        entity = excelParams.get(k);
        if (entity.getList() != null) {
            Collection<?> list = getListCellValue(entity, t);
            int listC = 0;
            if (list != null && list.size() > 0) {
                for (Object obj : list) {
                    createListCells(patriarch, index + listC, cellNum, obj, entity.getList(), sheet, workbook);
                    listC++;
                }
            }
            cellNum += entity.getList().size();
            if (list != null && list.size() > maxHeight) {
                maxHeight = list.size();
            }
        } else {
            Object value = getCellValue(entity, t);
            if (entity.getType() == BaseEntityTypeConstants.StringType) {
                createStringCell(row, cellNum++, value == null ? "" : value.toString(),
                        index % 2 == 0 ? getStyles(false, entity) : getStyles(true, entity), entity);
                if (entity.isHyperlink()) {
                    row.getCell(cellNum - 1).setHyperlink(dataHanlder.getHyperlink(
                            row.getSheet().getWorkbook().getCreationHelper(), t, entity.getName(), value));
                }
            } else if (entity.getType() == BaseEntityTypeConstants.DoubleType) {
                createDoubleCell(row, cellNum++, value == null ? "" : value.toString(),
                        index % 2 == 0 ? getStyles(false, entity) : getStyles(true, entity), entity);
                if (entity.isHyperlink()) {
                    row.getCell(cellNum - 1).setHyperlink(dataHanlder.getHyperlink(
                            row.getSheet().getWorkbook().getCreationHelper(), t, entity.getName(), value));
                }
            } else {
                createImageCell(patriarch, entity, row, cellNum++, value == null ? "" : value.toString(), t);
            }
        }
    }
    // ????
    cellNum = 0;
    for (int k = indexKey, paramSize = excelParams.size(); k < paramSize; k++) {
        entity = excelParams.get(k);
        if (entity.getList() != null) {
            cellNum += entity.getList().size();
        } else if (entity.isNeedMerge()) {
            for (int i = index + 1; i < index + maxHeight; i++) {
                sheet.getRow(i).createCell(cellNum);
                sheet.getRow(i).getCell(cellNum).setCellStyle(getStyles(false, entity));
            }
            sheet.addMergedRegion(new CellRangeAddress(index, index + maxHeight - 1, cellNum, cellNum));
            cellNum++;
        }
    }
    return maxHeight;

}

From source file:cn.bzvs.excel.export.ExcelExportServer.java

License:Apache License

/**
 *  ?//from  w  ww . j a  va 2 s.c o  m
 * 
 * @param entity
 * @param sheet
 * @param workbook
 * @param feildWidth
 */
public int createHeaderRow(ExportParams entity, Sheet sheet, Workbook workbook, int feildWidth) {
    Row row = sheet.createRow(0);
    row.setHeight(entity.getTitleHeight());
    createStringCell(row, 0, entity.getTitle(), getExcelExportStyler().getHeaderStyle(entity.getHeaderColor()),
            null);
    for (int i = 1; i <= feildWidth; i++) {
        createStringCell(row, i, "", getExcelExportStyler().getHeaderStyle(entity.getHeaderColor()), null);
    }
    sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, feildWidth));
    if (entity.getSecondTitle() != null) {
        row = sheet.createRow(1);
        row.setHeight(entity.getSecondTitleHeight());
        CellStyle style = workbook.createCellStyle();
        style.setAlignment(CellStyle.ALIGN_RIGHT);
        createStringCell(row, 0, entity.getSecondTitle(), style, null);
        for (int i = 1; i <= feildWidth; i++) {
            createStringCell(row, i, "", getExcelExportStyler().getHeaderStyle(entity.getHeaderColor()), null);
        }
        sheet.addMergedRegion(new CellRangeAddress(1, 1, 0, feildWidth));
        return 2;
    }
    return 1;
}

From source file:cn.bzvs.excel.export.ExcelExportServer.java

License:Apache License

/**
 * /*from ww  w .  j  a  va  2 s  .  co  m*/
 * 
 * @param title
 * @param index
 */
private int createTitleRow(ExportParams title, Sheet sheet, Workbook workbook, int index,
        List<ExcelExportEntity> excelParams) {
    Row row = sheet.createRow(index);
    int rows = getRowNums(excelParams);
    row.setHeight((short) 450);
    Row listRow = null;
    if (rows == 2) {
        listRow = sheet.createRow(index + 1);
        listRow.setHeight((short) 450);
    }
    int cellIndex = 0;
    CellStyle titleStyle = getExcelExportStyler().getTitleStyle(title.getColor());
    for (int i = 0, exportFieldTitleSize = excelParams.size(); i < exportFieldTitleSize; i++) {
        ExcelExportEntity entity = excelParams.get(i);
        if (StringUtils.isNotBlank(entity.getName())) {
            createStringCell(row, cellIndex, entity.getName(), titleStyle, entity);
        }
        if (entity.getList() != null) {
            List<ExcelExportEntity> sTitel = entity.getList();
            if (StringUtils.isNotBlank(entity.getName())) {
                sheet.addMergedRegion(
                        new CellRangeAddress(index, index, cellIndex, cellIndex + sTitel.size() - 1));
            }
            for (int j = 0, size = sTitel.size(); j < size; j++) {
                createStringCell(rows == 2 ? listRow : row, cellIndex, sTitel.get(j).getName(), titleStyle,
                        entity);
                cellIndex++;
            }
            cellIndex--;
        } else if (rows == 2) {
            createStringCell(listRow, cellIndex, "", titleStyle, entity);
            sheet.addMergedRegion(new CellRangeAddress(index, index + 1, cellIndex, cellIndex));
        }
        cellIndex++;
    }
    return rows;

}