Example usage for org.apache.poi.ss.usermodel Cell isPartOfArrayFormulaGroup

List of usage examples for org.apache.poi.ss.usermodel Cell isPartOfArrayFormulaGroup

Introduction

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

Prototype

boolean isPartOfArrayFormulaGroup();

Source Link

Usage

From source file:com.blackducksoftware.tools.commonframework.standard.protex.report.template.TemplateWriter.java

License:Apache License

/**
 * Write pojo values to row for the provided sheet.
 * // ww  w .jav a2  s  .c  o  m
 * @param activeSheet
 *            the provided sheet for pojo values write out to the rows
 * @param activeRow
 *            the active row
 * @param pojo
 *            the pojo
 * @param columnMap
 *            the column map
 * @param cloneStyle
 *            - if true, apply the styles to the new cells
 */
private void writePojoValuesToRow(Sheet activeSheet, Row activeRow, TemplatePojo pojo,
        Map<String, TemplateColumn> columnMap, boolean cloneStyle) {

    Iterator<String> it = columnMap.keySet().iterator();
    while (it.hasNext()) {
        String key = it.next();
        TemplateColumn column = columnMap.get(key);
        Integer position = column.getColumnPos();
        CellStyle styleFromTemplate = column.getCellStyle();

        Cell activeCell;
        int cellType = column.getCellType();
        if (cellType == Cell.CELL_TYPE_FORMULA) {
            activeCell = activeRow.createCell(position, Cell.CELL_TYPE_FORMULA);
            log.debug("Active Cell is PartOfArrayFormulaGroup: " + activeCell.isPartOfArrayFormulaGroup());
        } else if (cellType == Cell.CELL_TYPE_NUMERIC) {
            activeCell = activeRow.createCell(position, Cell.CELL_TYPE_NUMERIC);
        } else {
            activeCell = activeRow.createCell(position, Cell.CELL_TYPE_STRING);
        }

        // Set the value
        String pojoValue = getValueFromPojo(pojo, column.getLookupMappingName());
        activeCell.setCellValue(pojoValue);

        // Set the cell style
        // TODO: This catches the XML Disconnected exception, but the styles come out all wrong on subsequent
        // sheets.
        // Appears to only happen in the unit tests.
        if (cloneStyle) {
            try {
                CellStyle newcs = book.createCellStyle();
                newcs.cloneStyleFrom(styleFromTemplate);
                activeCell.setCellStyle(newcs);
            } catch (Exception e) {
                log.warn("Unable to copy cell styles!" + e.getMessage());
            }
        }

        if (cellType == Cell.CELL_TYPE_FORMULA) {
            copyFormula(activeSheet, activeCell, activeRow, column);
        }
    }
}