Example usage for org.apache.poi.hssf.usermodel HSSFRow createCell

List of usage examples for org.apache.poi.hssf.usermodel HSSFRow createCell

Introduction

In this page you can find the example usage for org.apache.poi.hssf.usermodel HSSFRow createCell.

Prototype

@Override
public HSSFCell createCell(int column) 

Source Link

Document

Use this to create new cells within the row and return it.

Usage

From source file:com.openitech.util.HSSFWrapper.java

License:Apache License

public static final HSSFWorkbook getWorkbook(JTable source, boolean countRows) {
    HSSFWorkbook xls_workbook = new HSSFWorkbook();
    HSSFSheet xls_sheet = xls_workbook.createSheet("Pregled podatkov");
    HSSFPrintSetup xls_sheet_printsetup = xls_sheet.getPrintSetup();
    xls_sheet_printsetup.setPaperSize(HSSFPrintSetup.A4_PAPERSIZE);
    xls_sheet_printsetup.setFitWidth((short) 1);

    TableColumnModel columnModel = source.getColumnModel();
    Enumeration<TableColumn> columns = columnModel.getColumns();

    HSSFRow xls_row = xls_sheet.createRow(0);
    short cell = 1;
    HSSFCellStyle xls_header_cell_style = xls_workbook.createCellStyle();
    HSSFFont xls_header_font = xls_workbook.createFont();

    xls_header_font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);

    xls_header_cell_style.setFont(xls_header_font);
    xls_header_cell_style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
    xls_header_cell_style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
    xls_header_cell_style.setFillForegroundColor(new HSSFColor.GREY_25_PERCENT().getIndex());
    //xls_header_cell_style.setBorderBottom(HSSFCellStyle.BORDER_DOUBLE);

    java.util.Map<String, HSSFCellStyle> cellStyles = new java.util.HashMap<String, HSSFCellStyle>();

    HSSFDataFormat xls_data_format = xls_workbook.createDataFormat();

    HSSFCellStyle xls_date_cell_style = xls_workbook.createCellStyle();
    xls_date_cell_style.setDataFormat(xls_data_format.getFormat("d.m.yyyy"));
    cellStyles.put("d.m.yyyy", xls_date_cell_style);

    HSSFCellStyle xls_double_cell_style = xls_workbook.createCellStyle();
    xls_double_cell_style.setDataFormat(xls_data_format.getFormat("#,##0.00"));
    cellStyles.put("#,##0.00", xls_double_cell_style);

    while (columns.hasMoreElements()) {
        TableColumn column = columns.nextElement();

        HSSFCell xls_cell = xls_row.createCell(cell++);
        xls_cell.setCellValue(new HSSFRichTextString(column.getHeaderValue().toString()));
        xls_cell.setCellStyle(xls_header_cell_style);
    }//  w w  w . j  av  a  2 s. co m

    TableModel tableModel = source.getModel();
    DbTableModel dbTableModel = (tableModel instanceof DbTableModel) ? (DbTableModel) tableModel : null;
    Integer fetchSize = null;

    if (dbTableModel != null) {
        try {
            fetchSize = dbTableModel.getDataSource().getFetchSize();
            dbTableModel.getDataSource().setFetchSize(2000);
        } catch (SQLException ex) {
            Logger.getLogger(HSSFWrapper.class.getName()).log(Level.WARNING, null, ex);
            fetchSize = null;
        }
    }

    short row = 1;

    JWProgressMonitor progress = new JWProgressMonitor((java.awt.Frame) null);

    progress.setTitle("Izvoz podatkov v Excel");
    progress.setMax(tableModel.getRowCount());

    progress.setVisible(true);

    try {
        while (row <= tableModel.getRowCount()) {
            xls_row = xls_sheet.createRow(row);
            cell = 0;

            HSSFCell xls_cell = xls_row.createCell(cell++);
            if (countRows) {
                xls_cell.setCellValue(new HSSFRichTextString(Short.toString(row)));
            }

            while (cell <= columnModel.getColumnCount()) {
                Object value = tableModel.getValueAt(source.convertRowIndexToModel(row - 1),
                        source.convertColumnIndexToModel(cell - 1));
                if (value != null) {
                    if (value instanceof DbTableModel.ColumnDescriptor.ValueMethod) {
                        DbTableModel.ColumnDescriptor.ValueMethod vm = (DbTableModel.ColumnDescriptor.ValueMethod) value;

                        if (vm.getColumnNames().size() == 1) {
                            java.util.List<Object> values = vm.getValues();
                            java.util.List<String> cellFormats = vm.getCellFormats();

                            for (String cellFormat : cellFormats) {
                                if (cellFormat != null) {
                                    if (!cellStyles.containsKey(cellFormat)) {
                                        HSSFCellStyle xls_cell_style = xls_workbook.createCellStyle();
                                        xls_cell_style.setDataFormat(xls_data_format.getFormat(cellFormat));
                                        cellStyles.put(cellFormat, xls_cell_style);
                                    }
                                }
                            }

                            Object vm_value = values.get(0);
                            HSSFCellStyle xls_cell_style = cellFormats.get(0) == null ? null
                                    : cellStyles.get(cellFormats.get(0));

                            if (vm_value != null) {
                                xls_cell = xls_row.createCell(cell);

                                if (vm_value instanceof java.util.Date) {
                                    xls_cell.setCellValue((java.util.Date) vm_value);
                                    xls_cell.setCellStyle(
                                            xls_cell_style == null ? xls_date_cell_style : xls_cell_style);
                                } else if (vm_value instanceof java.lang.Number) {
                                    xls_cell.setCellValue(((java.lang.Number) vm_value).doubleValue());
                                    if ((vm_value instanceof java.math.BigDecimal)
                                            || (vm_value instanceof java.lang.Double)
                                            || (vm_value instanceof java.lang.Float)) {
                                        xls_cell.setCellStyle(xls_cell_style == null ? xls_double_cell_style
                                                : xls_cell_style);
                                    }
                                } else if (vm_value instanceof java.lang.Boolean) {
                                    xls_cell.setCellValue(((java.lang.Boolean) vm_value).booleanValue());
                                } else {
                                    xls_cell.setCellValue(new HSSFRichTextString(value.toString()));
                                }
                            }
                        } else {
                            xls_cell = xls_row.createCell(cell);
                            xls_cell.setCellValue(new HSSFRichTextString(value.toString()));
                        }
                    } else {
                        xls_cell = xls_row.createCell(cell);
                        xls_cell.setCellValue(new HSSFRichTextString(value.toString()));
                    }
                }
                cell++;
            }

            row++;
            progress.next();
        }

        for (cell = 0; cell <= columnModel.getColumnCount(); cell++) {
            xls_sheet.autoSizeColumn(cell);
        }

        xls_sheet.createFreezePane(1, 1);
    } finally {
        progress.setVisible(false);

        if (fetchSize != null) {
            try {
                dbTableModel.getDataSource().setFetchSize(fetchSize);
            } catch (SQLException ex) {
                Logger.getLogger(HSSFWrapper.class.getName()).log(Level.WARNING, null, ex);
            }
        }
    }

    return xls_workbook;
}

From source file:com.project.jsica.cdi.ReporteBean.java

public void reporte2(List<ReportePermisoBean> reporte) {
    LOG.info("TAMAO reporte: " + reporte.size());
    FacesContext fc = FacesContext.getCurrentInstance();
    HttpServletResponse response = (HttpServletResponse) fc.getExternalContext().getResponse();

    HSSFWorkbook libro = new HSSFWorkbook();

    HSSFFont fuente = libro.createFont();
    fuente.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
    HSSFCellStyle estiloCeldaCabecera = libro.createCellStyle();
    estiloCeldaCabecera.setFont(fuente);
    estiloCeldaCabecera.setAlignment(HSSFCellStyle.ALIGN_CENTER);

    DataFormat format = libro.createDataFormat();

    HSSFCellStyle style = libro.createCellStyle();
    style.setDataFormat(format.getFormat("hh:mm:ss"));

    HSSFCellStyle fechas = libro.createCellStyle();
    fechas.setDataFormat(format.getFormat("dd.MM.yyyy"));

    HSSFSheet hoja = libro.createSheet("hoja 1");

    //CREAR LAS CABECERAS
    String[] cabeceras = { "CODIGO", "NOMBRE", "HORA INICIO", "HORA FIN", "HORAS", "MINUTOS", "FECHA",
            "MOTIVO" };

    HSSFRow filaCabecera = hoja.createRow(0);

    for (int x = 0; x < cabeceras.length; x++) {
        HSSFCell cabecera = filaCabecera.createCell(x);
        cabecera.setCellValue(cabeceras[x]);
        cabecera.setCellStyle(estiloCeldaCabecera);
    }/*from  ww w .j av a  2 s . com*/
    //FIN DE CABECERAS
    for (int i = 0; i < reporte.size(); i++) {

        HSSFRow fila = hoja.createRow(i + 1);

        HSSFCell columna1 = fila.createCell(0);
        columna1.setCellValue(reporte.get(i).getCodigo());

        HSSFCell columna2 = fila.createCell(1);
        columna2.setCellValue(reporte.get(i).getNombre());

        HSSFCell columna3 = fila.createCell(2);
        columna3.setCellValue(reporte.get(i).getHoraInicio());
        columna3.setCellStyle(style);

        HSSFCell columna4 = fila.createCell(3);
        columna4.setCellValue(reporte.get(i).getHoraFin());
        columna4.setCellStyle(style);

        HSSFCell columna5 = fila.createCell(4);
        columna5.setCellValue(reporte.get(i).getHoras());

        HSSFCell columna6 = fila.createCell(5);
        columna6.setCellValue(reporte.get(i).getMinutos());

        HSSFCell columna7 = fila.createCell(6);
        columna7.setCellValue(reporte.get(i).getFechaReal());
        columna7.setCellStyle(fechas);

        HSSFCell columna8 = fila.createCell(7);
        columna8.setCellValue(reporte.get(i).getMotivo());
    }

    try {

        OutputStream output = response.getOutputStream();

        libro.write(output);
        output.close();

        fc.responseComplete();

    } catch (IOException ex) {
        LOG.info("ERROR: " + ex);
    }
}

From source file:com.project.jsica.cdi.ReporteBean.java

public void reporte3() {
    if (nuevoReporte) {
        LOG.info("OPCION: " + opcionReporte);
        String nombreReporte = "";
        int filas = 0;
        if (opcionReporte == 2) {
            reporte = registroAsistenciaController.buscarXArea(areaSeleccionada, desde, hasta);
            LOG.info("TAMAO reporte: " + reporte.size());
            nombreReporte = "Reporte de asistencia por area";
            filas = 1;//  w  w  w  . ja  va 2  s.  c o m
        } else if (opcionReporte == 1) {
            reporte = registroAsistenciaController.buscarXEmpleado(empleado, desde, hasta);
            LOG.info("TAMAO reporte: " + reporte.size());
            nombreReporte = "Reporte de asistencia por empleado";
            filas = 0;
        }

        FacesContext fc = FacesContext.getCurrentInstance();
        HttpServletResponse response = (HttpServletResponse) fc.getExternalContext().getResponse();

        response.reset();
        response.setContentType("application/vnd.ms-excel");
        response.setHeader("Content-Disposition", "attachment; filename=" + nombreReporte + ".xls");

        HSSFWorkbook libro = new HSSFWorkbook();

        HSSFFont fuente = libro.createFont();
        fuente.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
        HSSFCellStyle estiloCeldaCabecera = libro.createCellStyle();
        estiloCeldaCabecera.setFont(fuente);
        estiloCeldaCabecera.setAlignment(HSSFCellStyle.ALIGN_CENTER);

        DataFormat format = libro.createDataFormat();

        HSSFCellStyle style = libro.createCellStyle();
        style.setDataFormat(format.getFormat("hh:mm:ss"));

        HSSFCellStyle fechas = libro.createCellStyle();
        fechas.setDataFormat(format.getFormat("dd.MM.yyyy"));

        HSSFSheet hoja = libro.createSheet("Reporte de Asistencias");

        //CREAR LAS CABECERAS
        String[] cabeceras = { "CODIGO", "APELLIDOS Y NOMBRES", "FECHA", "TIPO", "HORA DE INGRESO",
                "HORA DE SALIDA", "MARCACION DE ENTRADA", "MARCACION DE SALIDA", "TARDANZA(Minutos)",
                "SALIDA REFRIGERIO", "ENTRADA REFRIGERIO", "MARCACION SALIDA R", "MARCACION DE ENTRADA R",
                "TARDANZA(refrigerio)", "TARDANZA TOTAL" };

        if (filas == 1) {
            HSSFRow filaArea = hoja.createRow(0);
            HSSFCell Area = filaArea.createCell(0);
            Area.setCellValue("AREA");
            Area.setCellStyle(estiloCeldaCabecera);

            HSSFCell nombre = filaArea.createCell(1);
            nombre.setCellValue(areaSeleccionada.getNombre() + "");
        }

        HSSFRow filaCabecera = hoja.createRow(filas);

        for (int x = 0; x < cabeceras.length; x++) {
            HSSFCell cabecera = filaCabecera.createCell(x);
            cabecera.setCellValue(cabeceras[x]);
            cabecera.setCellStyle(estiloCeldaCabecera);
        }
        //FIN DE CABECERAS
        for (int i = filas; i < reporte.size(); i++) {

            HSSFRow fila = hoja.createRow(i + 1);

            HSSFCell columna1 = fila.createCell(0);
            columna1.setCellValue(reporte.get(i).getEmpleado().getCodigo());

            HSSFCell columna2 = fila.createCell(1);
            columna2.setCellValue(reporte.get(i).getEmpleado().getNombreCompleto());

            HSSFCell columna3 = fila.createCell(2);
            columna3.setCellValue(reporte.get(i).getFecha());
            columna3.setCellStyle(fechas);

            HSSFCell columna4 = fila.createCell(3);
            columna4.setCellValue(reporte.get(i).getTipo() + "");

            HSSFCell columna5 = fila.createCell(4);
            columna5.setCellValue(reporte.get(i).getHoraEntrada());
            columna5.setCellStyle(style);

            HSSFCell columna6 = fila.createCell(5);
            columna6.setCellValue(reporte.get(i).getHoraSalida());
            columna6.setCellStyle(style);

            HSSFCell columna7 = fila.createCell(6);
            if (reporte.get(i).getMarcacionInicio() != null) {
                columna7.setCellValue(reporte.get(i).getMarcacionInicio());
                columna7.setCellStyle(style);
            } else {
                columna7.setCellValue("No marco.");
            }

            HSSFCell columna8 = fila.createCell(7);
            if (reporte.get(i).getMarcacionFin() != null) {
                columna8.setCellValue(reporte.get(i).getMarcacionFin());
                columna8.setCellStyle(style);
            } else {
                columna8.setCellValue("No marco.");
            }

            HSSFCell columna9 = fila.createCell(8);
            int minutos = (int) ((reporte.get(i).getMilisTardanzaTotal() / (1000 * 60)) % 60);
            columna9.setCellValue(minutos);

            HSSFCell columna10 = fila.createCell(9);
            columna10.setCellValue(reporte.get(i).getHoraSalidaRefrigerio());
            columna10.setCellStyle(style);

            HSSFCell columna11 = fila.createCell(10);
            columna11.setCellValue(reporte.get(i).getHoraEntradaRefrigerio());
            columna11.setCellStyle(style);

            HSSFCell columna12 = fila.createCell(11);
            if (reporte.get(i).getMarcacionInicioRefrigerio() != null) {
                columna12.setCellValue(reporte.get(i).getMarcacionInicioRefrigerio());
                columna12.setCellStyle(style);
            } else {
                columna12.setCellValue("No marco.");
            }

            HSSFCell columna13 = fila.createCell(12);
            if (reporte.get(i).getMarcacionFinRefrigerio() != null) {
                columna13.setCellValue(reporte.get(i).getMarcacionFinRefrigerio());
                columna13.setCellStyle(style);
            } else {
                columna13.setCellValue("No marco.");
            }

            HSSFCell columna14 = fila.createCell(13);
            columna14.setCellValue((int) ((reporte.get(i).getMilisTardanzaRefrigerio() / (1000 * 60)) % 60));

            HSSFCell columna15 = fila.createCell(14);
            columna15.setCellValue((int) ((reporte.get(i).getMilisTardanzaTotalFinal() / (1000 * 60)) % 60));

        }

        try {
            OutputStream output = response.getOutputStream();

            libro.write(output);
            output.close();

            fc.responseComplete();
        } catch (IOException ex) {
            LOG.info("ERROR: " + ex);
        }

        nuevoReporte = false;
    }

}

From source file:com.pureinfo.dolphin.export.impl.ExcelExporterImpl.java

License:Open Source License

/**
 * Exports headers to excel.// w  ww  . j a va  2s. c  o  m
 * 
 * @param _sheet
 *            excel work sheet
 * @param _headers
 *            header titles
 */
public static void exportHeaders(HSSFSheet _sheet, String _headers[], HSSFCellStyle _headStyle)
        throws PureException {
    HSSFRow row = _sheet.createRow(0);
    for (short j = 0; j < _headers.length; j++) {
        _sheet.setColumnWidth(j, (short) 3000);
        HSSFCell cell = row.createCell(j);
        cell.setEncoding((short) 1);
        cell.setCellStyle(_headStyle);
        cell.setCellValue(_headers[j]);
    }
}

From source file:com.pureinfo.dolphin.export.impl.ExcelExporterImpl.java

License:Open Source License

/**
 * Exports a row to excel.//from  w  w w  .j  a va 2 s  .  c  o  m
 * 
 * @param _sheet
 *            excel work sheet
 * @param _cols
 *            columns values
 * @param _nRowNum
 *            row number
 * @param _dateStyle
 *            date style
 * @throws PureException
 *             if failed.
 */
public static void exportRow(HSSFSheet _sheet, Object[] _cols, int _nRowNum, HSSFCellStyle _dateStyle)
        throws PureException {
    HSSFCell cell;
    Object value;
    HSSFRow row = _sheet.createRow(_nRowNum);
    for (short nCol = 0; nCol < _cols.length; nCol++) {
        _sheet.setColumnWidth(nCol, (short) 3000);
        cell = row.createCell(nCol);
        cell.setEncoding((short) 1);
        value = _cols[nCol];
        if (value == null) {
            cell.setCellValue("");
        } else if (value instanceof String) {
            cell.setCellValue((String) value);
        } else if (value instanceof Number) {
            cell.setCellValue(((Number) value).doubleValue());
        } else if (value instanceof Boolean) {
            cell.setCellValue(((Boolean) value).booleanValue());
        } else if (value instanceof Date) {
            cell.setCellStyle(_dateStyle);
            cell.setCellValue((Date) value);
        } else if (value instanceof Calendar) {
            cell.setCellStyle(_dateStyle);
            cell.setCellValue((Calendar) value);
        } else {
            cell.setCellValue(value.toString());
        }

    }
}

From source file:com.pureinfo.srm.project.model.compile.helper.CompileExcelExportHelper.java

License:Open Source License

public static void exportRow(HSSFSheet _sheet, Object[] _cols, int _nRowNum, HSSFCellStyle _dateStyle,
        HSSFCellStyle _doubleStyle) throws PureException {
    HSSFCell cell;/*www.jav  a  2 s .c o  m*/
    Object value;
    HSSFRow row = _sheet.createRow(_nRowNum);
    for (short nCol = 0; nCol < _cols.length; nCol++) {
        _sheet.setColumnWidth(nCol, (short) 3000);
        cell = row.createCell(nCol);
        cell.setEncoding((short) 1);
        value = _cols[nCol];
        if (value == null) {
            cell.setCellValue("");
            style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
            cell.setCellStyle(style);

        } else if (value instanceof String) {
            cell.setCellValue((String) value);
            style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
            cell.setCellStyle(style);
        } else if (value instanceof Number) {
            cell.setCellValue(((Number) value).doubleValue());
            style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
            cell.setCellStyle(_doubleStyle);
        } else if (value instanceof Boolean) {
            cell.setCellValue(((Boolean) value).booleanValue());
            style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
            cell.setCellStyle(style);
        } else if (value instanceof Date) {
            cell.setCellValue((Date) value);
            cell.setCellStyle(_dateStyle);
        } else if (value instanceof Calendar) {
            cell.setCellValue((Calendar) value);
            cell.setCellStyle(_dateStyle);
        } else {
            cell.setCellValue(value.toString());
            style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
            cell.setCellStyle(style);
        }

    }
}

From source file:com.pureinfo.srm.project.model.compile.helper.CompileExcelExportHelper.java

License:Open Source License

public static void exportHeaders(HSSFSheet _sheet, String _headers[], HSSFCellStyle _headStyle)
        throws PureException {
    HSSFRow row = _sheet.createRow(0);
    for (short j = 0; j < _headers.length; j++) {
        _sheet.setColumnWidth(j, (short) 3000);
        HSSFCell cell = row.createCell(j);
        cell.setEncoding((short) 1);
        cell.setCellValue(_headers[j]);/*w  w w  . j a  va2s .com*/
        cell.setCellStyle(_headStyle);
    }
}

From source file:com.qcadoo.mes.assignmentToShift.print.xls.AssignmentToShiftXlsService.java

License:Open Source License

private void createHeaderForAuthor(final HSSFSheet sheet, final Locale locale, final Entity entity) {
    HSSFRow headerAuthorLine = sheet.createRow(1);

    String shift = translationService.translate(COLUMN_HEADER_SHIFT, locale) + " "
            + entity.getBelongsToField(SHIFT).getStringField(NAME);
    String user = translationService.translate(COLUMN_HEADER_AUTHOR, locale) + " "
            + entity.getField(CREATE_USER).toString();
    String date = translationService.translate(COLUMN_HEADER_UPDATE_DATE, locale) + " "
            + DateFormat.getDateInstance().format(entity.getField(UPDATE_DATE));

    HSSFCell cellAuthorLine0 = headerAuthorLine.createCell(0);
    cellAuthorLine0.setCellValue(shift);
    HSSFCell cellAuthorLine3 = headerAuthorLine.createCell(3);
    cellAuthorLine3.setCellValue(date);//from  w  w  w .j a va 2  s. co m
    HSSFCell cellAuthorLine6 = headerAuthorLine.createCell(6);
    cellAuthorLine6.setCellValue(user);

    headerAuthorLine.setHeightInPoints(30);

    assignmentToShiftXlsStyleHelper.addMarginsAndStylesForAuthor(sheet, 1,
            assignmentToShiftXlsHelper.getNumberOfDaysBetweenGivenDates(entity));

}

From source file:com.qcadoo.mes.assignmentToShift.print.xls.AssignmentToShiftXlsService.java

License:Open Source License

private void createHeaderForAssignmentToShift(final HSSFSheet sheet, final Locale locale, final Entity entity) {
    List<DateTime> days = assignmentToShiftXlsHelper.getDaysBetweenGivenDates(entity);

    if (days != null) {
        HSSFRow headerAssignmentToShift = sheet.createRow(3);

        String occupationType = translationService.translate(COLUMN_HEADER_OCCUPATIONTYPE, locale);

        HSSFCell cell0 = headerAssignmentToShift.createCell(0);
        cell0.setCellValue(occupationType);

        int columnNumber = 1;
        for (DateTime day : days) {
            HSSFCell cellDay = headerAssignmentToShift.createCell(columnNumber);

            cellDay.setCellValue(translationService.translate(COLUMN_HEADER_DAY, locale,
                    DateFormat.getDateInstance().format(new Date(day.getMillis()))));

            columnNumber += 3;//w ww  .  j  av  a 2s.  c  o m
        }

        headerAssignmentToShift.setHeightInPoints(14);

        assignmentToShiftXlsStyleHelper.addMarginsAndStylesForAssignmentToShift(sheet, 3,
                assignmentToShiftXlsHelper.getNumberOfDaysBetweenGivenDates(entity));
    }
}

From source file:com.qcadoo.mes.assignmentToShift.print.xls.AssignmentToShiftXlsService.java

License:Open Source License

private int fillColumnWithStaffForWorkOnLine(final HSSFSheet sheet, int rowNum,
        final Entity assignmentToShiftReport, final List<DateTime> days, final List<Entity> productionLines,
        final Entity dictionaryItem) {
    if ((assignmentToShiftReport != null) && (days != null) && (productionLines != null)) {

        for (Entity productionLine : productionLines) {
            int rowNumFromLastSection = rowNum;
            int numberOfColumnsForWorkers = getNumberOfRowsForWorkers(assignmentToShiftReport, days,
                    productionLine, dictionaryItem);
            for (int i = 0; i < numberOfColumnsForWorkers; i++) {
                HSSFRow row = sheet.createRow(rowNum);
                rowNum++;//from w w w  .j  a  va2 s .co  m
            }

            String productionLineValue = null;
            if (productionLine.getStringField(PLACE) == null) {
                productionLineValue = productionLine.getStringField(NUMBER);
            } else {
                productionLineValue = productionLine.getStringField(NUMBER) + "-"
                        + productionLine.getStringField(ProductionLineFields.PLACE);
            }
            HSSFRow firstRowInSection = null;
            if (sheet.getRow(rowNumFromLastSection) == null) {
                firstRowInSection = sheet.createRow(rowNumFromLastSection);
                rowNum++;
            } else {
                firstRowInSection = sheet.getRow(rowNumFromLastSection);

            }
            HSSFCell cell = firstRowInSection.createCell(0);
            cell.setCellValue(productionLineValue);
            sheet.addMergedRegion(new CellRangeAddress(rowNumFromLastSection, rowNum - 1, 0, 0));
            int columnNumber = 1;
            int maxLength = 0;

            for (DateTime day : days) {
                Entity assignmentToShift = assignmentToShiftXlsHelper
                        .getAssignmentToShift(assignmentToShiftReport.getBelongsToField(SHIFT), day.toDate());
                if (assignmentToShift == null) {
                    columnNumber += 3;
                    continue;
                }
                List<Entity> staffs = assignmentToShiftXlsHelper.getStaffsList(assignmentToShift,
                        dictionaryItem.getStringField(NAME), productionLine);
                if (staffs.isEmpty()) {
                    columnNumber += 3;
                    continue;
                }
                String staffsValue = assignmentToShiftXlsHelper.getListOfWorkers(staffs);

                List<String> workers = assignmentToShiftXlsHelper.getListOfWorker(staffs);

                int rowIndex = rowNumFromLastSection;

                for (String worker : workers) {
                    sheet.getRow(rowIndex).createCell(columnNumber).setCellValue(worker);
                    rowIndex++;
                }
                if (workers.isEmpty()) {
                    sheet.getRow(rowIndex).createCell(columnNumber).setCellValue(" ");

                }
                if (maxLength < staffsValue.length()) {
                    maxLength = staffsValue.length();
                }
                // row.setHeightInPoints(assignmentToShiftXlsStyleHelper.getHeightForRow(maxLength, 22, 14));
                columnNumber += 3;
            }
            for (int i = rowNumFromLastSection; i < rowNum; i++) {
                assignmentToShiftXlsStyleHelper.addMarginsAndStylesForSeries(sheet, i,
                        assignmentToShiftXlsHelper.getNumberOfDaysBetweenGivenDates(assignmentToShiftReport));

            }
        }

    }
    return rowNum;
}