Example usage for org.apache.poi.ss.usermodel Row getCell

List of usage examples for org.apache.poi.ss.usermodel Row getCell

Introduction

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

Prototype

Cell getCell(int cellnum, MissingCellPolicy policy);

Source Link

Document

Returns the cell at the given (0 based) index, with the specified org.apache.poi.ss.usermodel.Row.MissingCellPolicy

Usage

From source file:ch.oakmountain.tpa.parser.TpaParser.java

License:Apache License

public void generateRequests(MacroscopicTopology macroscopicTopology, int requestsPerHour, int durationMinutes,
        int offset, String from, String to, Periodicity p) {
    String colLayoutString = getPropertyValue(tpaProps.REQUESTS_COL_LAYOUT);

    List<ColumnIdentifier> cols = new ArrayList<ColumnIdentifier>(requestsLayout.values().length);
    for (requestsLayout l : requestsLayout.values()) {
        cols.add(l);//from w w  w  .ja  v a 2  s.c o  m
    }
    Map<ColumnIdentifier, Integer> colLayoutMapping = getColLayoutMapping(colLayoutString, cols);

    int arrtimeColIndex = colLayoutMapping.get(requestsLayout.ARRTIME);
    int fromColIndex = colLayoutMapping.get(requestsLayout.FROM);
    int toColIndex = colLayoutMapping.get(requestsLayout.TO);
    int deptimeColIndex = colLayoutMapping.get(requestsLayout.DEPTIME);
    int idColIndex = colLayoutMapping.get(requestsLayout.ID);
    String requestedMarker = getPropertyValue(tpaProps.REQUESTS_REQUESTED_DAY_MARKER);

    List<String> linkNames = macroscopicTopology.getLinkNames();
    Sheet sheet = wb.getSheet(getPropertyValue(tpaProps.REQUESTS_WS_NAME));

    // header
    Row headerRow = sheet.createRow(0);
    for (ColumnIdentifier col : colLayoutMapping.keySet()) {
        int i = colLayoutMapping.get(col);
        Cell cell = headerRow.getCell(i, Row.CREATE_NULL_AS_BLANK);
        cell.setCellValue(col.name());
    }
    // train path slots hourly
    int k = 1;
    for (int i = 0; i < 24; i++) {
        for (int j = 0; j < requestsPerHour; j++) {
            Row row = sheet.createRow(sheet.getLastRowNum() + 1);
            int hour = i;
            int minutes = (offset + j * (60 / requestsPerHour)) % 60;
            double deptime = DateUtil
                    .convertTime(String.format("%02d", hour) + ":" + String.format("%02d", minutes));
            double arrtime = (deptime * 24 * 60 + durationMinutes) / (24 * 60);

            Cell cell = row.getCell(deptimeColIndex, Row.CREATE_NULL_AS_BLANK);
            cell.setCellStyle(timestyle);
            cell.setCellValue(deptime);
            cell = row.getCell(arrtimeColIndex, Row.CREATE_NULL_AS_BLANK);
            cell.setCellStyle(timestyle);
            cell.setCellValue(arrtime);

            row.getCell(fromColIndex, Row.CREATE_NULL_AS_BLANK).setCellValue(from);
            row.getCell(toColIndex, Row.CREATE_NULL_AS_BLANK).setCellValue(to);

            row.getCell(idColIndex, Row.CREATE_NULL_AS_BLANK)
                    .setCellValue(from + "_" + to + "_" + String.format("%03d", k));
            k++;

            // peridiocity
            for (Integer integer : p.getWeekDays()) {
                int weekdayColIndex = colLayoutMapping.get(requestsLayout.getWeekDayTrainPathLayout(integer));
                row.getCell(weekdayColIndex, Row.CREATE_NULL_AS_BLANK).setCellValue(requestedMarker);
            }
        }
    }
}

From source file:ch.oakmountain.tpa.parser.TpaParser.java

License:Apache License

public void addCatalogue(MacroscopicTopology macroscopicTopology, TrainPathSlotCatalogue catalogue) {
    String colLayoutString = getPropertyValue(tpaProps.TRAINPATHS_COL_LAYOUT);
    List<ColumnIdentifier> cols = new ArrayList<ColumnIdentifier>(trainPathLayout.values().length);
    for (trainPathLayout l : trainPathLayout.values()) {
        cols.add(l);//from w w w .  j a  v a  2  s  .  c  o  m
    }
    Map<ColumnIdentifier, Integer> colLayoutMapping = getColLayoutMapping(colLayoutString, cols);
    int deptimeColIndex = colLayoutMapping.get(trainPathLayout.DEPTIME);
    int arrtimeColIndex = colLayoutMapping.get(trainPathLayout.ARRTIME);
    int idColIndex = colLayoutMapping.get(trainPathLayout.ID);

    for (PeriodicalTrainPathSlot periodicalTrainPathSlot : catalogue.getTrainPathSlots()) {
        String linkName = periodicalTrainPathSlot.getTrainPathSectionName();

        // Create sheet if it does not exist yet
        if (wb.getSheet(linkName) == null) {
            Sheet sheet = wb.createSheet(linkName);
            // header
            Row headerRow = sheet.createRow(0);
            for (ColumnIdentifier col : colLayoutMapping.keySet()) {
                int i = colLayoutMapping.get(col);
                Cell cell = headerRow.getCell(i, Row.CREATE_NULL_AS_BLANK);
                cell.setCellValue(col.name());
            }
        }

        Sheet sheet = wb.getSheet(linkName);
        int rowNb;
        for (rowNb = 1; rowNb < sheet.getPhysicalNumberOfRows(); rowNb++) {
            if (sheet.getRow(rowNb) == null || StringUtils.isBlank(
                    getCellValueString(sheet.getRow(rowNb).getCell(idColIndex, Row.CREATE_NULL_AS_BLANK)))) {
                break;
            }
        }
        Row row = sheet.createRow(rowNb);

        TrainPathSlot slot = periodicalTrainPathSlot.getSlots().get(0);
        int depHour = slot.getStartTime().getHourOfDay();
        int depMinutes = slot.getStartTime().getMinuteOfHour();
        int arrHour = slot.getEndTime().getHourOfDay();
        int arrMinutes = slot.getEndTime().getMinuteOfHour();
        double deptime = DateUtil
                .convertTime(String.format("%02d", depHour) + ":" + String.format("%02d", depMinutes));
        double arrtime = DateUtil
                .convertTime(String.format("%02d", arrHour) + ":" + String.format("%02d", arrMinutes));

        Cell cell = row.getCell(deptimeColIndex, Row.CREATE_NULL_AS_BLANK);
        cell.setCellStyle(timestyle);
        cell.setCellValue(deptime);
        cell = row.getCell(arrtimeColIndex, Row.CREATE_NULL_AS_BLANK);
        cell.setCellStyle(timestyle);
        cell.setCellValue(arrtime);

        cell = row.getCell(idColIndex, Row.CREATE_NULL_AS_BLANK);
        cell.setCellValue(periodicalTrainPathSlot.getName());
    }
}

From source file:com.accenture.control.ExcelDAO.java

public String[] carregaPlanilhaFuncionalidade() throws IOException, ClassNotFoundException, SQLException {

    Plano plano = new Plano();
    ManipulaDadosSQLite banco = new ManipulaDadosSQLite();
    String[] funcionalidade = null;
    try {// w  w w . j  av a 2  s. c o  m
        FileInputStream arquivo = new FileInputStream(new File(ExcelDAO.fileName));
        XSSFWorkbook workbook = new XSSFWorkbook(arquivo);
        //setado a planilha de configuraes
        XSSFSheet sheetPlano = workbook.getSheetAt(2);
        //linha pa
        int linha = 1;
        int coluna = 4;

        funcionalidade = new String[sheetPlano.getLastRowNum()];
        int index = 0;
        for (int count = 1; count < sheetPlano.getLastRowNum(); count++) {
            Row row = sheetPlano.getRow(count);
            for (int countColuna = 0; countColuna < 1; countColuna++) {
                Cell cell = row.getCell(coluna, Row.CREATE_NULL_AS_BLANK);
                System.out.println(cell.getColumnIndex() + "-" + cell.getRowIndex());
                if (cell.getCellType() == CELL_TYPE_BLANK) {
                    System.out.println("Campo vazio");
                } else if (cell.getCellType() == CELL_TYPE_NUMERIC) {
                    double valor = cell.getNumericCellValue();

                    System.out.println(valor);
                } else {
                    String valor = cell.getStringCellValue();
                    System.out.println(valor);
                    funcionalidade[index] = valor;
                    System.out.println(funcionalidade[index]);
                    banco.insertTabelaConf("TB_FUNCIONALIDADE", "DESC_FUNCIONALIDADE", valor);
                    index++;
                }
            }
        }

    } catch (FileNotFoundException ex) {
        Logger.getLogger(ExcelDAO.class.getName()).log(Level.SEVERE, null, ex);

    }
    return funcionalidade;
}

From source file:com.accenture.control.ExcelDAO.java

public String[] carregaPlanilhaSistemaMaster() throws IOException {

    Plano plano = new Plano();

    String[] sistemaMaster = null;
    try {/*from ww w  .jav a  2s . com*/
        FileInputStream arquivo = new FileInputStream(new File(ExcelDAO.fileName));
        XSSFWorkbook workbook = new XSSFWorkbook(arquivo);
        //setado a planilha de configuraes
        XSSFSheet sheetPlano = workbook.getSheetAt(2);
        //linha pa
        int linha = 1;
        int coluna = 2;

        sistemaMaster = new String[sheetPlano.getLastRowNum()];
        int index = 0;
        for (int count = 1; count < sheetPlano.getLastRowNum(); count++) {
            Row row = sheetPlano.getRow(count);
            for (int countColuna = 0; countColuna < 1; countColuna++) {
                Cell cell = row.getCell(coluna, Row.CREATE_NULL_AS_BLANK);
                System.out.println(cell.getColumnIndex() + "-" + cell.getRowIndex());
                if (cell.getCellType() == CELL_TYPE_BLANK) {
                    System.out.println("Campo vazio");
                } else if (cell.getCellType() == CELL_TYPE_NUMERIC) {
                    double valor = cell.getNumericCellValue();
                    System.out.println(valor);
                } else {
                    String valor = cell.getStringCellValue();
                    System.out.println(valor);
                    sistemaMaster[index] = valor;
                    System.out.println(sistemaMaster[index]);
                    index++;
                }
            }
        }

    } catch (FileNotFoundException ex) {
        Logger.getLogger(ExcelDAO.class.getName()).log(Level.SEVERE, null, ex);
    }
    return sistemaMaster;
}

From source file:com.alibaba.ims.platform.util.ExcelUtil.java

License:Open Source License

/**
 * ?//from   www.  j  av  a2s.com
 *
 * @param workbook
 * @return
 */
private static List<String[]> readFromWorkbook(Workbook workbook) {
    List<String[]> rowList = new ArrayList<String[]>();
    if (workbook == null) {
        return rowList;
    }

    Sheet sheet = workbook.getSheetAt(0);
    if (sheet.getPhysicalNumberOfRows() <= 0) {
        return rowList;
    }

    for (Row row : sheet) {
        int last = Math.min(row.getLastCellNum(), 20);
        String[] rowContent = new String[last];
        for (int i = 0; i < last; i++) {
            Cell cell = row.getCell(i, Row.RETURN_BLANK_AS_NULL);
            if (cell != null) {
                rowContent[i] = getCellValue(cell);
            }
        }
        rowList.add(rowContent);
    }
    return rowList;
}

From source file:com.asakusafw.testdata.generator.excel.SheetEditor.java

License:Apache License

private Cell getCell(Sheet sheet, int rowIndex, int columnIndex) {
    assert sheet != null;
    Row row = sheet.getRow(rowIndex);
    if (row == null) {
        row = sheet.createRow(rowIndex);
    }/*from w ww  . j a va  2s  . c  o  m*/
    Cell cell = row.getCell(columnIndex, Row.CREATE_NULL_AS_BLANK);
    return cell;
}

From source file:com.asakusafw.testdriver.excel.ExcelSheetDataModelSource.java

License:Apache License

@Override
public DataModelReflection next() throws IOException {
    while (nextRowNumber <= sheet.getLastRowNum()) {
        Row row = sheet.getRow(nextRowNumber++);
        if (row == null) {
            LOG.warn(MessageFormat.format(Messages.getString("ExcelSheetDataModelSource.warnSkipEmptyRow"), //$NON-NLS-1$
                    id, nextRowNumber));
            continue;
        }/*from  w  w w  .jav  a 2  s  .c  o m*/
        boolean sawFilled = false;
        ExcelDataDriver driver = new ExcelDataDriver(definition, id);
        for (Map.Entry<PropertyName, Integer> entry : names.entrySet()) {
            Cell cell = row.getCell(entry.getValue(), Row.CREATE_NULL_AS_BLANK);
            int type = cell.getCellType();
            if (type == Cell.CELL_TYPE_FORMULA) {
                evaluateInCell(cell);
                type = cell.getCellType();
            }
            if (type == Cell.CELL_TYPE_ERROR) {
                throw new IOException(
                        MessageFormat.format(Messages.getString("ExcelSheetDataModelSource.errorErroneousCell"), //$NON-NLS-1$
                                id, row.getRowNum() + 1, cell.getColumnIndex() + 1));
            }
            sawFilled |= (type != Cell.CELL_TYPE_BLANK);
            driver.process(entry.getKey(), cell);
        }
        if (sawFilled) {
            return driver.getReflection();
        } else {
            LOG.warn(MessageFormat.format(Messages.getString("ExcelSheetDataModelSource.warnSkipEmptyRow"), //$NON-NLS-1$
                    id, row.getRowNum() + 1));
        }
    }
    return null;
}

From source file:com.b2international.snowowl.datastore.server.importer.TerminologyImportExcelParser.java

License:Apache License

private int getMemberStartIndex(final Sheet sheet, final int propertyIndex) {

    int i = propertyIndex;

    while (i < sheet.getLastRowNum()) {

        final Row row = sheet.getRow(i);

        if (null != row) {

            final String value = ExcelUtilities
                    .extractContentAsString(row.getCell(0, Row.CREATE_NULL_AS_BLANK));

            if (!StringUtils.isEmpty(value)
                    && (value.equalsIgnoreCase("code") || value.equalsIgnoreCase("effective time"))) {
                break;
            }/*from  ww w .  jav a  2  s  .  c  o  m*/

        }

        i++;

    }

    return i;

}

From source file:com.b2international.snowowl.datastore.server.importer.TerminologyImportExcelParser.java

License:Apache License

private LinkedList<String> processProperties(final Sheet sheet, final int propertyIndex) {
    final LinkedList<String> componentProperties = Lists.newLinkedList();
    for (int i = 0; i < propertyIndex; i++) {
        final Row row = sheet.getRow(i);
        if (row != null) {
            componentProperties//from www.  j a v a 2  s.c om
                    .add(ExcelUtilities.extractContentAsString(row.getCell(1, Row.CREATE_NULL_AS_BLANK)));
        }
    }
    return componentProperties;
}

From source file:com.b2international.snowowl.datastore.server.importer.TerminologyImportExcelParser.java

License:Apache License

private Multimap<String, String> processKeywords(Sheet sheet, int propertyIndex, int memberStartIndex) {

    final Multimap<String, String> componentMetadata = HashMultimap.create();

    for (int i = propertyIndex + 1; i < memberStartIndex - 1; i++) {

        final Row row = sheet.getRow(i);

        if (null != row) {

            final String groupName = ExcelUtilities
                    .extractContentAsString(row.getCell(0, Row.CREATE_NULL_AS_BLANK));
            final String keyword = ExcelUtilities
                    .extractContentAsString(row.getCell(1, Row.CREATE_NULL_AS_BLANK));

            if (!groupName.isEmpty()) {

                componentMetadata.put(groupName, keyword);

            }/* w ww.  j  ava2 s .com*/

        }
    }

    return componentMetadata;

}