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

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

Introduction

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

Prototype

void setCellValue(boolean value);

Source Link

Document

Set a boolean value for the cell

Usage

From source file:com.biomeris.i2b2.export.engine.ExcelCreator.java

License:Open Source License

public void writeAggregates(Map<String, List<ConceptAggregate>> patientAggregate, int conceptNumber,
        boolean maskPatientids) {
    Set<Integer> usedColumns = new HashSet<>();

    for (String patientId : patientAggregate.keySet()) {
        Row row = currentSheet.createRow(currentSheetRow++);

        // 0//from  w w  w  .j av a 2 s.co m
        if (maskPatientids) {
            Integer maskedId;
            if (maskedPatientMaps.containsKey(patientId)) {
                maskedId = maskedPatientMaps.get(patientId);
            } else {
                maskedId = nextMaskedId;
                maskedPatientMaps.put(patientId, nextMaskedId++);
            }
            row.createCell(0).setCellValue(maskedId);
        } else {
            row.createCell(0).setCellValue(patientId);
        }
        usedColumns.add(0);

        for (int i = 0; i < patientAggregate.get(patientId).size(); i++) {
            ConceptAggregate ca = patientAggregate.get(patientId).get(i);

            if (ca == null) {
                row.createCell((i * 5) + 1).setCellStyle(leftSeparatorStyle);
                row.createCell((i * 5) + 2);
                row.createCell((i * 5) + 3);
                row.createCell((i * 5) + 4);
                row.createCell((i * 5) + 5);
                continue;
            }

            // (i*5)+1
            Cell countCell = row.createCell((i * 5) + 1);
            countCell.setCellStyle(leftSeparatorStyle);
            if (ca.getCount() != null) {
                countCell.setCellValue(ca.getCount());
                usedColumns.add((i * 5) + 1);
            }
            // (i*5)+2
            if (ca.getMean() != null) {
                row.createCell((i * 5) + 2).setCellValue(ca.getMean());
                usedColumns.add((i * 5) + 2);
            }
            // (i*5)+3
            if (ca.getSd() != null) {
                row.createCell((i * 5) + 3).setCellValue(ca.getSd());
                usedColumns.add((i * 5) + 3);
            }
            // (i*5)+4
            if (ca.getMedian() != null) {
                row.createCell((i * 5) + 4).setCellValue(ca.getMedian());
                usedColumns.add((i * 5) + 4);
            }
            // (i*5)+5
            if (ca.getMode() != null) {
                row.createCell((i * 5) + 5).setCellValue(ca.getMode());
                usedColumns.add((i * 5) + 5);
            }
        }

    }

    int colNum = (conceptNumber * 5) + 1;
    for (int i = 0; i < colNum; i++) {
        if (!usedColumns.contains(i)) {
            currentSheet.setColumnHidden(i, true);
        }
    }
}

From source file:com.biomeris.i2b2.export.engine.ExcelCreator.java

License:Open Source License

public void writePatientInfo(List<WPatientInfo> patientInfos, PatientSheetElements pse,
        boolean maskPatientids) {
    for (WPatientInfo pInfo : patientInfos) {
        Row row = currentSheet.createRow(currentSheetRow++);

        int colIndex = 0;

        if (maskPatientids) {
            String patientId = pInfo.getPatientId();
            Integer maskedId;//from w w  w.  j a va2 s  .c  om
            if (maskedPatientMaps.containsKey(patientId)) {
                maskedId = maskedPatientMaps.get(patientId);
            } else {
                maskedId = nextMaskedId;
                maskedPatientMaps.put(patientId, nextMaskedId++);
            }
            row.createCell(colIndex++).setCellValue(maskedId);
        } else {
            row.createCell(colIndex++).setCellValue(pInfo.getPatientId());
        }

        if (pse == null || pse.isVitalStatus()) {
            row.createCell(colIndex++).setCellValue(pInfo.getVitalStatus());
        }

        if (pse == null || pse.isBirthDate()) {
            if (pInfo.getDateOfBirth() != null) {
                Cell cell = row.createCell(colIndex++);
                cell.setCellStyle(dateStyle);
                cell.setCellValue(pInfo.getDateOfBirth().getTime());

                row.createCell(colIndex++).setCellValue(getAge(pInfo.getDateOfBirth()));
            } else {
                colIndex = colIndex + 2;
            }
        }

        if (pse == null || pse.isDeathDate()) {
            if (pInfo.getDateOfDeath() != null) {
                Cell cell = row.createCell(colIndex++);
                cell.setCellStyle(dateStyle);
                cell.setCellValue(pInfo.getDateOfDeath().getTime());
            } else {
                colIndex++;
            }
        }
        if (pse == null || pse.isSex()) {
            if (pInfo.getSex() != null) {
                row.createCell(colIndex++).setCellValue(pInfo.getSex());
            } else {
                colIndex++;
            }
        }
        if (pse == null || pse.isLanguage()) {
            if (pInfo.getLanguage() != null) {
                row.createCell(colIndex++).setCellValue(pInfo.getLanguage());
            } else {
                colIndex++;
            }
        }
        if (pse == null || pse.isRace()) {
            if (pInfo.getRace() != null) {
                row.createCell(colIndex++).setCellValue(pInfo.getRace());
            } else {
                colIndex++;
            }
        }
        if (pse == null || pse.isMaritalStatus()) {
            if (pInfo.getMaritalStatus() != null) {
                row.createCell(colIndex++).setCellValue(pInfo.getMaritalStatus());
            } else {
                colIndex++;
            }

        }
        if (pse == null || pse.isReligion()) {
            if (pInfo.getReligion() != null) {
                row.createCell(colIndex++).setCellValue(pInfo.getReligion());
            } else {
                colIndex++;
            }

        }
        if (pse == null || pse.isZipCode()) {
            if (pInfo.getZipCode() != null) {
                row.createCell(colIndex++).setCellValue(pInfo.getZipCode());
            } else {
                colIndex++;
            }

        }
        if (pse == null || pse.isIncome()) {
            if (pInfo.getIncome() != null) {
                row.createCell(colIndex++).setCellValue(pInfo.getIncome());
            } else {
                colIndex++;
            }

        }
    }
}

From source file:com.biomeris.i2b2.export.engine.ExcelCreator.java

License:Open Source License

public void writeExportInfo(WExport export) {
    // User/*from  w  w w . j  a  v  a2  s .com*/
    Row rowUser = currentSheet.createRow(currentSheetRow++);
    rowUser.createCell(0).setCellValue("User");
    rowUser.createCell(1).setCellValue(export.getUsername());

    // Export date
    Row rowDate = currentSheet.createRow(currentSheetRow++);
    rowDate.createCell(0).setCellValue("Export date");
    Cell todayCell = rowDate.createCell(1);
    todayCell.setCellStyle(dateStyle);
    todayCell.setCellValue(new Date());

    // Export type
    Row rowET = currentSheet.createRow(currentSheetRow++);
    rowET.createCell(0).setCellValue("Export type");
    rowET.createCell(1).setCellValue(export.getExportParams().getExportType());

    // Concepts and modifiers
    int conceptNum = 1;
    for (Concept c : export.getConcepts()) {
        Row rowC1 = currentSheet.createRow(currentSheetRow++);
        rowC1.createCell(0).setCellValue("Concept " + conceptNum + " (name)");
        rowC1.createCell(1).setCellValue(c.getName());
        Row rowC2 = currentSheet.createRow(currentSheetRow++);
        rowC2.createCell(0).setCellValue("Concept " + conceptNum + " (key)");
        rowC2.createCell(1).setCellValue(c.getItemKey());
        if (c.getModifier() != null) {
            Row rowM1 = currentSheet.createRow(currentSheetRow++);
            rowM1.createCell(0).setCellValue("Concept " + conceptNum + " (modifier name)");
            rowM1.createCell(1).setCellValue(c.getModifier().getName());
            Row rowM2 = currentSheet.createRow(currentSheetRow++);
            rowM2.createCell(0).setCellValue("Concept " + conceptNum + " (modifier key)");
            rowM2.createCell(1).setCellValue(c.getModifier().getModifierKey());
        }
        conceptNum++;
    }

    // Filter date ( min start date)
    if (export.getExportParams().getStartDate() != null) {
        Row rowSD = currentSheet.createRow(currentSheetRow++);
        rowSD.createCell(0).setCellValue("Min start date");
        Cell sdCell = rowSD.createCell(1);
        sdCell.setCellStyle(dateStyle);
        sdCell.setCellValue(export.getExportParams().getStartDate().getTime());
    }

    // Filter date (max start date)
    if (export.getExportParams().getEndDate() != null) {
        Row rowED = currentSheet.createRow(currentSheetRow++);
        rowED.createCell(0).setCellValue("Max start date");
        Cell sdCell = rowED.createCell(1);
        sdCell.setCellStyle(dateStyle);
        sdCell.setCellValue(export.getExportParams().getEndDate().getTime());
    }
}

From source file:com.bizosys.dataservice.dao.ReadXLS.java

License:Apache License

@Override
protected List<String> populate() throws SQLException {

    checkCondition();// w w w.  j  a  va 2 s. c  o m

    Workbook workbook = getWorkbook();
    Sheet sheet = workbook.createSheet();

    ResultSetMetaData md = rs.getMetaData();
    int totalCol = md.getColumnCount();
    String[] cols = createLabels(md, totalCol);

    try {

        if (null != templateFile) {
            File templateFileObject = new File(templateFile);
            if (templateFileObject.exists()) {
                Workbook templateWorkbook = new HSSFWorkbook(new FileInputStream(templateFileObject));
                Sheet templatesheet = templateWorkbook.getSheetAt(0);
                Iterator<Row> rowIterator = templatesheet.iterator();

                while (rowIterator.hasNext()) {
                    Row templateRow = rowIterator.next();
                    Row row = sheet.createRow(startRowIndex++);

                    Iterator<Cell> cellIterator = templateRow.cellIterator();
                    while (cellIterator.hasNext()) {
                        Cell templateCell = cellIterator.next();
                        Cell cell = row.createCell(templateCell.getColumnIndex());
                        cell.setCellType(templateCell.getCellType());
                        switch (templateCell.getCellType()) {
                        case Cell.CELL_TYPE_BLANK:
                            break;
                        case Cell.CELL_TYPE_BOOLEAN:
                            cell.setCellValue(templateCell.getBooleanCellValue());
                            break;
                        case Cell.CELL_TYPE_ERROR:
                            cell.setCellValue(templateCell.getErrorCellValue());
                            break;
                        case Cell.CELL_TYPE_FORMULA:
                            cell.setCellValue(templateCell.getCellFormula());
                            break;
                        case Cell.CELL_TYPE_NUMERIC:
                            cell.setCellValue(templateCell.getNumericCellValue());
                            break;
                        case Cell.CELL_TYPE_STRING:
                            cell.setCellValue(templateCell.getStringCellValue());
                            break;
                        }
                    }
                }
            } else {
                System.err.println("Can not read " + templateFileObject.getAbsolutePath());
            }

        }

        while (this.rs.next()) {
            createRecord(totalCol, cols, sheet);
        }
        workbook.write(out);
    } catch (IOException ex) {
        throw new SQLException(ex);
    }
    return null;
}

From source file:com.bizosys.dataservice.dao.ReadXLS.java

License:Apache License

private void createRecord(int colsT, String[] cols, Sheet sheet) throws SQLException {

    Object colObj = null;//from   w  ww .  ja  v a2s .  c om
    String colStr = null;

    Row row = sheet.createRow(startRowIndex++);
    for (int colI = 0; colI < colsT; colI++) {
        colObj = rs.getObject(colI + 1);
        colStr = (null == colObj) ? EMPTY_STRING : colObj.toString().trim();
        Cell cell = row.createCell(colI);
        cell.setCellValue(colStr);
    }
}

From source file:com.bizosys.dataservice.dao.ReadXLS.java

License:Apache License

private void writeHeader(String[] headerCols, Sheet sheet) {
    Row headerRow = sheet.createRow(startRowIndex++);
    int cellIndex = 0;
    for (String aCol : headerCols) {
        Cell headerCell = headerRow.createCell(cellIndex++);
        headerCell.setCellValue(aCol);
    }//  w ww  .j  av a2 s  . c  o m
}

From source file:com.bizosys.dataservice.dao.WriteToXls.java

License:Apache License

public void write(List<Object[]> records) throws Exception {
    Workbook workbook = getWorkbook();// w  w w.j a  va  2 s .c  o m
    Sheet sheet = workbook.createSheet();

    if (null != templateFile) {
        File templateFileObject = new File(templateFile);
        if (templateFileObject.exists()) {
            Workbook templateWorkbook = new HSSFWorkbook(new FileInputStream(templateFileObject));
            Sheet templatesheet = templateWorkbook.getSheetAt(0);
            Iterator<Row> rowIterator = templatesheet.iterator();

            while (rowIterator.hasNext()) {
                Row templateRow = rowIterator.next();
                Row row = sheet.createRow(startRowIndex++);

                Iterator<Cell> cellIterator = templateRow.cellIterator();
                while (cellIterator.hasNext()) {
                    Cell templateCell = cellIterator.next();
                    Cell cell = row.createCell(templateCell.getColumnIndex());
                    cell.setCellType(templateCell.getCellType());
                    switch (templateCell.getCellType()) {
                    case Cell.CELL_TYPE_BLANK:
                        break;
                    case Cell.CELL_TYPE_BOOLEAN:
                        cell.setCellValue(templateCell.getBooleanCellValue());
                        break;
                    case Cell.CELL_TYPE_ERROR:
                        cell.setCellValue(templateCell.getErrorCellValue());
                        break;
                    case Cell.CELL_TYPE_FORMULA:
                        cell.setCellValue(templateCell.getCellFormula());
                        break;
                    case Cell.CELL_TYPE_NUMERIC:
                        cell.setCellValue(templateCell.getNumericCellValue());
                        break;
                    case Cell.CELL_TYPE_STRING:
                        cell.setCellValue(templateCell.getStringCellValue());
                        break;
                    }
                }
            }
        } else {
            System.err.println("Can not read " + templateFileObject.getAbsolutePath());
        }
    }

    for (Object[] cols : records) {
        createRecord(cols, sheet);
    }
    workbook.write(out);

}

From source file:com.bizosys.dataservice.dao.WriteToXls.java

License:Apache License

private void createRecord(Object[] cols, Sheet sheet) throws SQLException {

    String colStr = null;/*from  ww  w  . j  a v  a  2 s  .  c  om*/

    Row row = sheet.createRow(startRowIndex++);
    int colI = 0;
    for (Object colObj : cols) {
        colStr = (null == colObj) ? EMPTY_STRING : colObj.toString().trim();
        Cell cell = row.createCell(colI);
        cell.setCellValue(colStr);
        colI++;
    }
}

From source file:com.blackducksoftware.tools.commonframework.standard.datatable.writer.DataSetWriterExcel.java

License:Apache License

private Sheet initNewSheet(RecordDef recordDef) {
    Sheet sheet = workbook.createSheet();
    // Write header row
    Row row = sheet.createRow(0);/*w w w.j av  a2s.  c o  m*/
    int cellIndex = 0;
    for (FieldDef fieldDef : recordDef) {
        Cell cell = row.createCell(cellIndex++);
        String cellValue = fieldDef.getDescription();
        cell.setCellValue(cellValue);
    }
    return sheet;
}

From source file:com.blackducksoftware.tools.commonframework.standard.datatable.writer.DataSetWriterExcel.java

License:Apache License

private void populateStringCell(Record record, FieldDef fieldDef, Cell cell) throws Exception {
    String cellValue = record.getStringFieldValue(fieldDef.getName());
    cell.setCellValue(cellValue);
}