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

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

Introduction

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

Prototype

int getRowNum();

Source Link

Document

Get row number this row represents

Usage

From source file:fr.openwide.core.export.excel.AbstractExcelTableExport.java

License:Apache License

/**
 * Ajoute une cellule texte./*from  w  w  w.jav  a 2s  .c  o m*/
 * 
 * @param row ligne
 * @param columnIndex numro de la colonne
 * @param text texte  insrer dans la cellule
 * @return cellule
 */
protected Cell addTextCell(Row row, int columnIndex, String text) {
    Cell cell = row.createCell(columnIndex);
    cell.setCellStyle(getRowStyle(STYLE_STANDARD_NAME, row.getRowNum()));
    cell.setCellType(Cell.CELL_TYPE_STRING);
    cell.setCellValue(creationHelper.createRichTextString(normalizeLineBreaks(text == null ? "" : text)));

    return cell;
}

From source file:fr.openwide.core.export.excel.AbstractExcelTableExport.java

License:Apache License

/**
 * Ajoute une cellule formule.//  w  w  w. j av  a2  s  .co m
 * 
 * @param row ligne
 * @param columnIndex numro de la colonne
 * @param formula formule  insrer dans la cellule
 * @return cellule
 */
protected Cell addFormulaCell(Row row, int columnIndex, String formula) {
    Cell cell = row.createCell(columnIndex);
    cell.setCellStyle(getRowStyle(STYLE_STANDARD_NAME, row.getRowNum()));
    cell.setCellType(Cell.CELL_TYPE_FORMULA);
    cell.setCellFormula(formula);

    return cell;
}

From source file:fr.openwide.core.export.excel.AbstractExcelTableExport.java

License:Apache License

/**
 * Ajoute une cellule au format date./*  ww w  . jav  a  2  s .co  m*/
 * 
 * @param row ligne
 * @param columnIndex numro de la colonne
 * @param date date  insrer dans la cellule
 * @return cellule
 */
protected Cell addDateCell(Row row, int columnIndex, Date date) {
    Cell cell = row.createCell(columnIndex);
    cell.setCellStyle(getRowStyle(STYLE_DATE_NAME, row.getRowNum()));
    if (date != null) {
        cell.setCellValue(date);
    }

    return cell;
}

From source file:fr.openwide.core.export.excel.AbstractExcelTableExport.java

License:Apache License

/**
 * Ajoute une cellule au format date + heure.
 * /*  w  w  w .  ja v a  2 s  . c  o  m*/
 * @param row ligne
 * @param columnIndex numro de la colonne
 * @param date date  insrer dans la cellule
 * @return cellule
 */
protected Cell addDateTimeCell(Row row, int columnIndex, Date date) {
    Cell cell = row.createCell(columnIndex);
    cell.setCellStyle(getRowStyle(STYLE_DATE_TIME_NAME, row.getRowNum()));
    if (date != null) {
        cell.setCellValue(date);
    }

    return cell;
}

From source file:fr.openwide.core.export.excel.AbstractExcelTableExport.java

License:Apache License

/**
 * Ajoute une cellule contenant un nombre entier.
 * //from  w  w  w  .ja va2s. co m
 * @param row ligne
 * @param columnIndex numro de la colonne
 * @param number nombre  insrer dans la cellule
 * @return cellule
 */
protected Cell addIntegerCell(Row row, int columnIndex, Number number) {
    Cell cell = row.createCell(columnIndex);
    cell.setCellType(Cell.CELL_TYPE_NUMERIC);
    cell.setCellStyle(getRowStyle(STYLE_INTEGER_NAME, row.getRowNum()));

    if (number != null) {
        cell.setCellValue(number.doubleValue());
    }

    return cell;
}

From source file:fr.openwide.core.export.excel.AbstractExcelTableExport.java

License:Apache License

/**
 * Ajoute une cellule contenant un nombre dcimal.
 * //from  w w w .java  2  s .c om
 * @param row ligne
 * @param columnIndex numro de la colonne
 * @param number nombre  insrer dans la cellule
 * @return cellule
 */
protected Cell addDecimalCell(Row row, int columnIndex, Number number) {
    Cell cell = row.createCell(columnIndex);
    cell.setCellType(Cell.CELL_TYPE_NUMERIC);
    cell.setCellStyle(getRowStyle(STYLE_DECIMAL_NAME, row.getRowNum()));

    if (number != null) {
        cell.setCellValue(number.doubleValue());
    }

    return cell;
}

From source file:fr.openwide.core.export.excel.AbstractExcelTableExport.java

License:Apache License

/**
 * Ajoute une cellule contenant un pourcentage.
 * /*from w ww. j  a  v  a  2s . c o  m*/
 * @param row ligne
 * @param columnIndex numro de la colonne
 * @param number nombre  insrer dans la cellule
 * @return cellule
 */
protected Cell addPercentCell(Row row, int columnIndex, Number number) {
    Cell cell = row.createCell(columnIndex);
    cell.setCellType(Cell.CELL_TYPE_NUMERIC);
    cell.setCellStyle(getRowStyle(STYLE_PERCENT_NAME, row.getRowNum()));

    if (number != null) {
        cell.setCellValue(number.doubleValue());
    }

    return cell;
}

From source file:fr.openwide.core.export.excel.AbstractExcelTableExport.java

License:Apache License

/**
 * Ajoute une cellule contenant un pourcentage avec signe +/-.
 * //from ww  w  .j  ava 2s .  co  m
 * @param row ligne
 * @param columnIndex numro de la colonne
 * @param number nombre  insrer dans la cellule
 * @return cellule
 */
protected Cell addPercentRelativeCell(Row row, int columnIndex, Number number) {
    Cell cell = row.createCell(columnIndex);
    cell.setCellType(Cell.CELL_TYPE_NUMERIC);
    cell.setCellStyle(getRowStyle(STYLE_PERCENT_RELATIVE_NAME, row.getRowNum()));

    if (number != null) {
        cell.setCellValue(number.doubleValue());
    }

    return cell;
}

From source file:fr.openwide.core.export.excel.AbstractExcelTableExport.java

License:Apache License

/**
 * Ajoute une cellule contenant une taille de fichier
 * /*from   ww  w.ja  va 2s .  com*/
 * @param row ligne
 * @param columnIndex numro de la colonne
 * @param fileSizeInBytes taille de fichier en octets
 * @return cellule
 */
protected Cell addFileSizeCell(Row row, int columnIndex, Long fileSizeInBytes) {
    Cell cell = row.createCell(columnIndex);
    cell.setCellType(Cell.CELL_TYPE_NUMERIC);
    cell.setCellStyle(getRowStyle(STYLE_FILE_SIZE_NAME, row.getRowNum()));

    if (fileSizeInBytes != null) {
        cell.setCellValue(fileSizeInBytes);
    }

    return cell;
}

From source file:fr.paris.lutece.plugins.appointment.service.ClosingDayService.java

License:Open Source License

/**
 * Import the closing dates of a given file
 * // w  ww . j  a va2 s  . c o m
 * @param item
 *            the file in input
 * @return the list of the closing dates in the file
 * @throws IOException
 *             if error during reading file
 */
public static List<LocalDate> getImportClosingDays(FileItem item) throws IOException {
    HashSet<LocalDate> listDays = new HashSet<LocalDate>();
    FileInputStream fis = null;
    Workbook workbook = null;
    String strExtension = FilenameUtils.getExtension(item.getName());
    if (StringUtils.equals(MARK_EXCEL_EXTENSION_XLSX, strExtension)) {
        try {
            fis = (FileInputStream) item.getInputStream();
            // Using XSSF for xlsx format, for xls use HSSF
            workbook = new XSSFWorkbook(fis);
            int numberOfSheets = workbook.getNumberOfSheets();
            // looping over each workbook sheet
            for (int i = 0; i < numberOfSheets; i++) {
                Sheet sheet = workbook.getSheetAt(i);
                Iterator<Row> rowIterator = sheet.iterator();
                // iterating over each row
                while (rowIterator.hasNext()) {
                    Row row = (Row) rowIterator.next();
                    if (row.getRowNum() > 1) {
                        Iterator<Cell> cellIterator = row.cellIterator();
                        // Iterating over each cell (column wise) in a
                        // particular row.
                        while (cellIterator.hasNext()) {
                            Cell cell = (Cell) cellIterator.next();
                            // The Cell Containing String will is name.
                            if (cell.getColumnIndex() == 3) {
                                String strdate = StringUtils.EMPTY;
                                if (cell.getCellType() == 0) {
                                    Instant instant = cell.getDateCellValue().toInstant();
                                    LocalDate localDate = instant.atZone(ZoneId.systemDefault()).toLocalDate();
                                    strdate = localDate.format(Utilities.getFormatter());
                                }
                                if (StringUtils.isNotEmpty(strdate)
                                        && strdate.matches(MARK_FORMAT_DATE_REGEX)) {
                                    LocalDate date = LocalDate.parse(strdate, Utilities.getFormatter());
                                    listDays.add(date);
                                }
                            }
                        }
                    }
                }
            }
        } finally {
            if (fis != null) {
                fis.close();
            }
            if (workbook != null) {
                workbook.close();
            }
        }
    }
    return new ArrayList<LocalDate>(listDays);
}