Example usage for org.apache.poi.xssf.usermodel XSSFCell getRichStringCellValue

List of usage examples for org.apache.poi.xssf.usermodel XSSFCell getRichStringCellValue

Introduction

In this page you can find the example usage for org.apache.poi.xssf.usermodel XSSFCell getRichStringCellValue.

Prototype

@Override
public XSSFRichTextString getRichStringCellValue() 

Source Link

Document

Get the value of the cell as a XSSFRichTextString

For numeric cells we throw an exception.

Usage

From source file:org.xframium.application.ExcelApplicationProvider.java

License:Open Source License

/**
 * Gets the cell value./*from ww w .  ja  v a2 s.  c o m*/
 *
 * @param cell the cell
 * @return the cell value
 */
private String getCellValue(XSSFCell cell) {
    if (cell != null) {
        switch (cell.getCellType()) {
        case XSSFCell.CELL_TYPE_BLANK:
            return null;
        case XSSFCell.CELL_TYPE_BOOLEAN:
            return String.valueOf(cell.getBooleanCellValue());
        case XSSFCell.CELL_TYPE_NUMERIC:
            return String.valueOf(cell.getNumericCellValue());
        case XSSFCell.CELL_TYPE_STRING:
            return cell.getRichStringCellValue().toString();
        }
    }
    return null;
}

From source file:org.xframium.device.data.ExcelDataProvider.java

License:Open Source License

/**
 * Gets the cell value.//www.java  2  s.co  m
 *
 * @param cell the cell
 * @return the cell value
 */
private String getCellValue(XSSFCell cell) {
    if (cell != null) {
        switch (cell.getCellType()) {
        case XSSFCell.CELL_TYPE_BLANK:
            return null;
        case XSSFCell.CELL_TYPE_BOOLEAN:
            return String.valueOf(cell.getBooleanCellValue());
        case XSSFCell.CELL_TYPE_NUMERIC:
            return String.valueOf((int) cell.getNumericCellValue());
        case XSSFCell.CELL_TYPE_STRING:
            return cell.getRichStringCellValue().toString();

        }
    }
    return null;
}

From source file:org.xframium.page.keyWord.provider.ExcelKeyWordProvider.java

License:Open Source License

private String getCellValue(XSSFCell cell) {
    if (cell != null) {
        switch (cell.getCellType()) {
        case XSSFCell.CELL_TYPE_BLANK:
            return null;
        case XSSFCell.CELL_TYPE_BOOLEAN:
            return String.valueOf(cell.getBooleanCellValue());
        case XSSFCell.CELL_TYPE_NUMERIC:
            return String.valueOf(cell.getNumericCellValue());
        case XSSFCell.CELL_TYPE_STRING:
            return cell.getRichStringCellValue().toString();
        }/*from   w w  w  . jav a  2 s. com*/
    }
    return null;
}

From source file:sv.com.mined.sieni.controller.GestionNotasController.java

public static void copyRow(XSSFSheet worksheetSource, XSSFSheet worksheetDestination, int sourceRowNum,
        int destinationRowNum) {
    // Get the source / new row
    XSSFRow origen = worksheetSource.getRow(sourceRowNum);
    XSSFRow destino = worksheetDestination.createRow(destinationRowNum);

    // Loop through source columns to add to new row
    for (int i = 0; i < origen.getLastCellNum(); i++) {
        // Grab a copy of the old/new cell
        XSSFCell oldCell = origen.getCell(i);
        XSSFCell newCell = destino.createCell(i);
        // If the old cell is null jump to next cell
        if (oldCell == null) {
            newCell = null;//from w ww  .  j a  v a2s  .co m
            continue;
        }

        //Ajustar tamaos columnas
        worksheetDestination.setColumnWidth(i, worksheetSource.getColumnWidth(i));

        // Copy style from old cell and apply to new cell
        XSSFCellStyle newCellStyle = newCell.getSheet().getWorkbook().createCellStyle();
        newCellStyle.cloneStyleFrom(oldCell.getCellStyle());
        newCell.setCellStyle(newCellStyle);

        // If there is a cell comment, copy
        if (oldCell.getCellComment() != null) {
            newCell.setCellComment(oldCell.getCellComment());
        }

        // If there is a cell hyperlink, copy
        if (oldCell.getHyperlink() != null) {
            newCell.setHyperlink(oldCell.getHyperlink());
        }

        // Set the cell data type
        newCell.setCellType(oldCell.getCellType());
        // Set the cell data value
        switch (oldCell.getCellType()) {
        case Cell.CELL_TYPE_BLANK:
            newCell.setCellValue(oldCell.getStringCellValue());
            break;
        case Cell.CELL_TYPE_BOOLEAN:
            newCell.setCellValue(oldCell.getBooleanCellValue());
            break;
        case Cell.CELL_TYPE_ERROR:
            newCell.setCellErrorValue(oldCell.getErrorCellValue());
            break;
        case Cell.CELL_TYPE_FORMULA:
            newCell.setCellFormula(oldCell.getCellFormula());
            break;
        case Cell.CELL_TYPE_NUMERIC:
            newCell.setCellValue(oldCell.getNumericCellValue());
            break;
        case Cell.CELL_TYPE_STRING:
            newCell.setCellValue(oldCell.getRichStringCellValue());
            break;
        }

    }

}

From source file:tan.jam.jsf.Shifting.java

private static void CopyData(XSSFWorkbook workbook, XSSFSheet worksheet, int sourceRowNum,
        int destinationRowNum, int Mov) {
    XSSFRow newRow = worksheet.getRow(destinationRowNum);
    XSSFRow sourceRow = worksheet.getRow(sourceRowNum);

    for (int i = sourceRow.getLastCellNum(); i > 8 + Mov; i--) {

        int d = i - 1;
        XSSFCell oldCell = sourceRow.getCell(d);
        XSSFCell newCell = newRow.createCell(i);

        if (oldCell == null) {
            newCell = null;/* w  w  w .  j  av a  2 s .  c  om*/
            continue;
        }

        XSSFCellStyle newCellStyle = workbook.createCellStyle();
        newCellStyle.cloneStyleFrom(oldCell.getCellStyle());
        ;
        newCell.setCellStyle(newCellStyle);

        if (oldCell.getCellComment() != null) {
            newCell.setCellComment(oldCell.getCellComment());
        }

        if (oldCell.getHyperlink() != null) {
            newCell.setHyperlink(oldCell.getHyperlink());
        }

        newCell.setCellType(oldCell.getCellType());

        switch (oldCell.getCellType()) {
        case org.apache.poi.ss.usermodel.Cell.CELL_TYPE_BLANK:
            newCell.setCellValue(oldCell.getStringCellValue());
            break;
        case org.apache.poi.ss.usermodel.Cell.CELL_TYPE_BOOLEAN:
            newCell.setCellValue(oldCell.getBooleanCellValue());
            break;
        case org.apache.poi.ss.usermodel.Cell.CELL_TYPE_ERROR:
            newCell.setCellErrorValue(oldCell.getErrorCellValue());
            break;
        case org.apache.poi.ss.usermodel.Cell.CELL_TYPE_FORMULA:
            newCell.setCellFormula(oldCell.getCellFormula());
            break;
        case org.apache.poi.ss.usermodel.Cell.CELL_TYPE_NUMERIC:
            newCell.setCellValue(oldCell.getNumericCellValue());
            break;
        case org.apache.poi.ss.usermodel.Cell.CELL_TYPE_STRING:
            newCell.setCellValue(oldCell.getRichStringCellValue());
            break;
        }
    }
}

From source file:utils.ReadWriteExcelFile.java

public static void readXLSXFile(String aFile, int SheetNo) throws IOException {

    InputStream ExcelFileToRead = new FileInputStream(aFile);
    XSSFWorkbook wb = new XSSFWorkbook(ExcelFileToRead);

    XSSFWorkbook test = new XSSFWorkbook();

    XSSFSheet sheet = wb.getSheetAt(SheetNo);
    XSSFRow row;/*www. j  av a2  s  .c o  m*/
    XSSFCell cell;
    CTSheetDimension dimension = sheet.getCTWorksheet().getDimension();
    String sheetDimensions = dimension.getRef();
    System.out.println(sheetDimensions);
    List<String> dimensions = StringUtils.split(sheetDimensions, ":", true);
    String[] Dimensions = dimensions.get(1).toString().split("(?<=\\D)(?=\\d)");
    int Colums = CharToInt(Dimensions[0]);
    int Rows = Integer.parseInt(Dimensions[1]);
    System.out.println();
    Iterator rows = sheet.rowIterator();
    ArrayList[][] TableName = new ArrayList[Rows][Colums];
    System.out.println(TableName.length);
    int currentRow = 0;
    while (rows.hasNext()) {

        row = (XSSFRow) rows.next();
        Iterator cells = row.cellIterator();
        int currentCell = 0;
        //         System.out.println("currentRow="+currentRow+" And Current Colum is ="+currentCell);
        while (cells.hasNext()) {
            cell = (XSSFCell) cells.next();

            if (cell.getStringCellValue().isEmpty()) {
                TableName[cell.getRowIndex()][cell.getColumnIndex()].add(" - ");
                //               System.out.print(cell.getStringCellValue()+" ");
                //                                        TableName[currentRow][currentCell].add(" ");
                //            System.out.println("Cell Value is : "+cell.toString());
                //                                System.out.println("Empty cell currentRow="+currentRow+" And Current Colum is ="+currentCell);

            } else if (cell.getCellType() == XSSFCell.CELL_TYPE_STRING) {
                System.out.println("current Row=" + cell.getRowIndex() + " And Current Colum is ="
                        + cell.getColumnIndex());
                System.out.println(cell.getRichStringCellValue());
                TableName[cell.getRowIndex()][cell.getColumnIndex()]
                        .add(cell.getRichStringCellValue().toString());
                //                                    System.out.println("Cell Type is :"+cell.getCellType());
                //                                    System.out.println("Cell Value is : "+cell.getRichStringCellValue());
            } else if (cell.getCellType() == XSSFCell.CELL_TYPE_NUMERIC) {
                TableName[cell.getRowIndex()][cell.getColumnIndex()].add(cell.getNumericCellValue());
                //                                    System.out.println("Cell Type is :"+cell.getCellType());
                //                                    System.out.println("current Row="+cell.getRowIndex()+" And Current Colum is ="+cell.getColumnIndex());
                //                                    int numericValue = (int) cell.getNumericCellValue();
                //                                    System.out.println("Cell Value is : "+numericValue);

            }
            //            else
            //            {
            //               //U Can Handel Boolean, Formula, Errors
            //            }
            currentCell++;
        }
        System.out.println();
        currentRow++;
    }
    for (int i = 0; TableName.length > i; i++) {
        for (int j = 0; TableName[i].length > j; j++) {
            System.out.println(TableName[i][j].toString());
        }

    }
}