Example usage for org.apache.poi.hssf.usermodel HSSFSheet createRow

List of usage examples for org.apache.poi.hssf.usermodel HSSFSheet createRow

Introduction

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

Prototype

@Override
public HSSFRow createRow(int rownum) 

Source Link

Document

Create a new row within the sheet and return the high level representation

Usage

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

License:Open Source License

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

        int rowNumFromLastSection = rowNum;

        int numberOfColumnsForWorkers = getNumberOfRowsForWorkersForOtherTypes(assignmentToShiftReport, days,
                occupationType);//w  w w  .j a va 2  s.co m
        for (int i = 0; i < numberOfColumnsForWorkers; i++) {
            HSSFRow row = sheet.createRow(rowNum);
            rowNum++;
        }
        String occupationTypeValue = occupationType.getStringField(NAME);

        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(occupationTypeValue);
        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,
                    occupationType.getStringField(NAME), null);

            List<String> workers = Lists.newArrayList();
            if (OccupationType.OTHER_CASE.getStringValue()
                    .equals(occupationType.getStringField(TECHNICAL_CODE))) {
                workers = assignmentToShiftXlsHelper.getListOfWorkerWithOtherCases(staffs);
            } else {
                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(" ");

            }
            columnNumber += 3;
        }

        for (int i = rowNumFromLastSection; i < rowNum; i++) {
            assignmentToShiftXlsStyleHelper.addMarginsAndStylesForSeries(sheet, i,
                    assignmentToShiftXlsHelper.getNumberOfDaysBetweenGivenDates(assignmentToShiftReport));
        }
    }

    return rowNum;
}

From source file:com.qcadoo.mes.materialFlow.print.xls.MaterialFlowXlsService.java

License:Open Source License

@Override
protected void addHeader(final HSSFSheet sheet, final Locale locale, final Entity entity) {
    HSSFRow header = sheet.createRow(0);
    HSSFCell cell0 = header.createCell(0);
    cell0.setCellValue(/*  www . j  a v a2s.co m*/
            translationService.translate("materialFlow.materialFlow.report.columnHeader.number", locale));
    xlsHelper.setCellStyle(sheet, cell0);
    HSSFCell cell1 = header.createCell(1);
    cell1.setCellValue(
            translationService.translate("materialFlow.materialFlow.report.columnHeader.name", locale));
    xlsHelper.setCellStyle(sheet, cell1);
    HSSFCell cell2 = header.createCell(2);
    cell2.setCellValue(
            translationService.translate("materialFlow.materialFlow.report.columnHeader.quantity", locale));
    xlsHelper.setCellStyle(sheet, cell2);
    HSSFCell cell3 = header.createCell(3);
    cell3.setCellValue(
            translationService.translate("materialFlow.materialFlow.report.columnHeader.unit", locale));
    xlsHelper.setCellStyle(sheet, cell3);
}

From source file:com.qcadoo.mes.materialFlow.print.xls.MaterialFlowXlsService.java

License:Open Source License

@Override
protected void addSeries(final HSSFSheet sheet, final Entity materialsInLocation) {
    Map<Entity, BigDecimal> reportData = materialFlowService
            .calculateMaterialQuantitiesInLocation(materialsInLocation);

    int rowNum = 1;
    for (Map.Entry<Entity, BigDecimal> data : reportData.entrySet()) {
        HSSFRow row = sheet.createRow(rowNum++);
        row.createCell(0).setCellValue(data.getKey().getStringField(NUMBER));
        row.createCell(1).setCellValue(data.getKey().getStringField(NAME));
        row.createCell(2).setCellValue(numberService.format(data.getValue()));
        row.createCell(3).setCellValue(data.getKey().getStringField(UNIT));
    }//w  w  w .j  av a2  s  .  c  o m
    sheet.autoSizeColumn((short) 0);
    sheet.autoSizeColumn((short) 1);
    sheet.autoSizeColumn((short) 2);
    sheet.autoSizeColumn((short) 3);
}

From source file:com.qcadoo.mes.materialRequirements.print.xls.MaterialRequirementXlsService.java

License:Open Source License

@Override
protected void addHeader(final HSSFSheet sheet, final Locale locale, final Entity materialRequirement) {
    HSSFRow header = sheet.createRow(0);
    HSSFCell cell0 = header.createCell(0);
    cell0.setCellValue(translationService.translate("basic.product.number.label", locale));
    xlsHelper.setCellStyle(sheet, cell0);
    HSSFCell cell1 = header.createCell(1);
    cell1.setCellValue(translationService.translate("basic.product.name.label", locale));
    xlsHelper.setCellStyle(sheet, cell1);
    HSSFCell cell2 = header.createCell(2);
    cell2.setCellValue(//from   w  w w  . j a v  a2s .co m
            translationService.translate("technologies.technologyOperationComponent.quantity.label", locale));
    xlsHelper.setCellStyle(sheet, cell2);
    HSSFCell cell3 = header.createCell(3);
    cell3.setCellValue(translationService.translate("basic.product.unit.label", locale));
    xlsHelper.setCellStyle(sheet, cell3);
}

From source file:com.qcadoo.mes.materialRequirements.print.xls.MaterialRequirementXlsService.java

License:Open Source License

@Override
protected void addSeries(final HSSFSheet sheet, final Entity materialRequirement) {
    int rowNum = 1;
    List<Entity> orders = materialRequirement.getManyToManyField(MaterialRequirementFields.ORDERS);
    MrpAlgorithm algorithm = MrpAlgorithm
            .parseString(materialRequirement.getStringField(MaterialRequirementFields.MRP_ALGORITHM));

    Map<Long, BigDecimal> neededProductQuantities = productQuantitiesService.getNeededProductQuantities(orders,
            algorithm, true);/*from  w  w  w  .  j a  v a 2s .  c o  m*/

    // TODO LUPO fix comparator
    // neededProductQuantities = SortUtil.sortMapUsingComparator(neededProductQuantities, new EntityNumberComparator());

    for (Entry<Long, BigDecimal> neededProductQuantity : neededProductQuantities.entrySet()) {
        Entity product = productQuantitiesService.getProduct(neededProductQuantity.getKey());

        HSSFRow row = sheet.createRow(rowNum++);
        row.createCell(0).setCellValue(product.getStringField(ProductFields.NUMBER));
        row.createCell(1).setCellValue(product.getStringField(ProductFields.NAME));
        row.createCell(2).setCellValue(numberService.setScale(neededProductQuantity.getValue()).doubleValue());
        String unit = product.getStringField(ProductFields.UNIT);
        if (unit == null) {
            row.createCell(3).setCellValue("");
        } else {
            row.createCell(3).setCellValue(unit);
        }
    }
    sheet.autoSizeColumn((short) 0);
    sheet.autoSizeColumn((short) 1);
    sheet.autoSizeColumn((short) 2);
    sheet.autoSizeColumn((short) 3);
}

From source file:com.qcadoo.mes.qualityControls.print.QualityControlForBatchXlsView.java

License:Open Source License

private void addOrderHeader(final HSSFSheet sheet, final Locale locale) {
    HSSFRow header = sheet.createRow(0);
    HSSFCell cell0 = header.createCell(0);
    cell0.setCellValue(//from w  w  w  .  j a v  a 2 s .co m
            translationService.translate("qualityControls.qualityControl.report.product.number", locale));
    xlsHelper.setCellStyle(sheet, cell0);
    HSSFCell cell1 = header.createCell(1);
    cell1.setCellValue(translationService.translate(
            "qualityControlsForBatch.qualityControlsForBatchList.window.mainTab.qualityControlsForBatch.column.batchNr",
            locale));
    xlsHelper.setCellStyle(sheet, cell1);
    HSSFCell cell2 = header.createCell(2);
    cell2.setCellValue(translationService.translate(
            "qualityControlsForBatch.qualityControlsForBatchList.window.mainTab.qualityControlsForBatch.column.number",
            locale));
    xlsHelper.setCellStyle(sheet, cell2);
    HSSFCell cell3 = header.createCell(3);
    cell3.setCellValue(translationService.translate(
            "qualityControlsForBatch.qualityControlForBatchDetails.window.mainTab.qualityControlForBatch.controlledQuantity.label",
            locale));
    xlsHelper.setCellStyle(sheet, cell3);
    HSSFCell cell4 = header.createCell(4);
    cell4.setCellValue(translationService.translate(
            "qualityControlsForBatch.qualityControlForBatchDetails.window.mainTab.qualityControlForBatch.rejectedQuantity.label",
            locale));
    xlsHelper.setCellStyle(sheet, cell4);
    HSSFCell cell5 = header.createCell(5);
    cell5.setCellValue(translationService.translate(
            "qualityControlsForBatch.qualityControlForBatchDetails.window.mainTab.qualityControlForBatch.acceptedDefectsQuantity.label",
            locale));
    xlsHelper.setCellStyle(sheet, cell5);
}

From source file:com.qcadoo.mes.qualityControls.print.QualityControlForBatchXlsView.java

License:Open Source License

private void addOrderSeries(final Map<String, Object> model, final HSSFSheet sheet) {
    int rowNum = 1;
    Map<Entity, List<Entity>> productOrders = qualityControlsReportService.getQualityOrdersForProduct(
            qualityControlsReportService.getOrderSeries(model, "qualityControlsForBatch"));
    productOrders = SortUtil.sortMapUsingComparator(productOrders, new EntityNumberComparator());
    for (Entry<Entity, List<Entity>> entry : productOrders.entrySet()) {
        List<Entity> orders = entry.getValue();
        Collections.sort(orders, new EntityBatchNumberComparator());
        for (Entity order : orders) {
            HSSFRow row = sheet.createRow(rowNum++);
            row.createCell(0)/*from   w  ww .  jav  a 2 s.co m*/
                    .setCellValue(entry.getKey() == null ? "" : entry.getKey().getStringField("number"));
            row.createCell(1).setCellValue(
                    order.getStringField("batchNr") == null ? "" : order.getStringField("batchNr"));
            row.createCell(2).setCellValue(order.getStringField("number"));
            row.createCell(3).setCellValue(
                    numberService.setScale(order.getDecimalField("controlledQuantity")).doubleValue());
            row.createCell(4).setCellValue(
                    numberService.setScale(order.getDecimalField("rejectedQuantity")).doubleValue());
            row.createCell(5).setCellValue(
                    numberService.setScale(order.getDecimalField("acceptedDefectsQuantity")).doubleValue());
        }
    }
    sheet.autoSizeColumn((short) 0);
    sheet.autoSizeColumn((short) 1);
    sheet.autoSizeColumn((short) 2);
    sheet.autoSizeColumn((short) 3);
    sheet.autoSizeColumn((short) 4);
    sheet.autoSizeColumn((short) 5);
}

From source file:com.qcadoo.mes.qualityControls.print.QualityControlForOperationXlsView.java

License:Open Source License

private void addOrderHeader(final HSSFSheet sheet, final Locale locale) {
    HSSFRow header = sheet.createRow(0);
    HSSFCell cell0 = header.createCell(0);
    cell0.setCellValue(// w w w .j a  v  a  2 s. c  o  m
            translationService.translate("qualityControls.qualityControl.report.operation.number", locale));
    xlsHelper.setCellStyle(sheet, cell0);
    HSSFCell cell1 = header.createCell(1);
    cell1.setCellValue(translationService.translate(
            "qualityControlsForOperation.qualityControlForOperationDetails.window.mainTab.qualityControlForOperation.number.label",
            locale));
    xlsHelper.setCellStyle(sheet, cell1);
    HSSFCell cell2 = header.createCell(2);
    cell2.setCellValue(translationService.translate(
            "qualityControlsForOperation.qualityControlForOperationDetails.window.mainTab.qualityControlForOperation.controlResult.label",
            locale));
    xlsHelper.setCellStyle(sheet, cell2);
}

From source file:com.qcadoo.mes.qualityControls.print.QualityControlForOperationXlsView.java

License:Open Source License

private void addOrderSeries(final Map<String, Object> model, final HSSFSheet sheet, final Locale locale) {
    int rowNum = 1;
    Map<Entity, List<Entity>> operationOrders = qualityControlsReportService.getQualityOrdersForOperation(
            qualityControlsReportService.getOrderSeries(model, "qualityControlsForOperation"));
    operationOrders = SortUtil.sortMapUsingComparator(operationOrders, new EntityNumberComparator());
    for (Entry<Entity, List<Entity>> entry : operationOrders.entrySet()) {
        List<Entity> orders = entry.getValue();
        Collections.sort(orders, new EntityNumberComparator());
        for (Entity order : orders) {
            HSSFRow row = sheet.createRow(rowNum++);
            row.createCell(0)/*from   ww  w  . java2 s  .c  o m*/
                    .setCellValue(entry.getKey() == null ? "" : entry.getKey().getStringField("nodeNumber"));
            row.createCell(1).setCellValue(order.getStringField("number"));
            String result = "";
            if ("01correct".equals(order.getField("controlResult"))) {
                result = translationService
                        .translate("qualityControls.qualityControl.controlResult.value.01correct", locale);
            } else if ("02incorrect".equals(order.getField("controlResult"))) {
                result = translationService
                        .translate("qualityControls.qualityControl.controlResult.value.02incorrect", locale);
            } else if ("03objection".equals(order.getField("controlResult"))) {
                result = translationService
                        .translate("qualityControls.qualityControl.controlResult.value.03objection", locale);
            }
            row.createCell(2).setCellValue(result);
        }
    }
    sheet.autoSizeColumn((short) 0);
    sheet.autoSizeColumn((short) 1);
    sheet.autoSizeColumn((short) 2);
}

From source file:com.qcadoo.mes.qualityControls.print.QualityControlForOrderXlsView.java

License:Open Source License

private void addOrderHeader(final HSSFSheet sheet, final Locale locale) {
    HSSFRow header = sheet.createRow(0);
    HSSFCell cell0 = header.createCell(0);
    cell0.setCellValue(/*ww  w.j av  a 2 s . c  o m*/
            translationService.translate("qualityControls.qualityControl.report.product.number", locale));
    xlsHelper.setCellStyle(sheet, cell0);
    HSSFCell cell1 = header.createCell(1);
    cell1.setCellValue(translationService.translate(
            "qualityControls.qualityControlForOrderDetails.window.mainTab.qualityControlForOrder.number.label",
            locale));
    xlsHelper.setCellStyle(sheet, cell1);
    HSSFCell cell2 = header.createCell(2);
    cell2.setCellValue(translationService.translate(
            "qualityControls.qualityControlForOrderDetails.window.qualityControlForOrder.controlResult.label",
            locale));
    xlsHelper.setCellStyle(sheet, cell2);
}