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

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

Introduction

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

Prototype

RichTextString getRichStringCellValue();

Source Link

Document

Get the value of the cell as a XSSFRichTextString

For numeric cells we throw an exception.

Usage

From source file:midas.sheeco.type.adapter.SpreadsheetBooleanAdapterTest.java

License:Apache License

@Test
public void testStringNo() {
    SpreadsheetBooleanAdapter adapter = new SpreadsheetBooleanAdapter();

    Cell cell = mock(Cell.class);
    when(cell.getCellType()).thenReturn(Cell.CELL_TYPE_STRING);
    when(cell.getRichStringCellValue()).thenReturn(new HSSFRichTextString("nO"));

    Boolean value = adapter.fromSpreadsheet(cell);
    Assert.assertFalse(value);/*from   w w w .j ava 2s.  com*/
}

From source file:midas.sheeco.type.adapter.SpreadsheetBooleanAdapterTest.java

License:Apache License

@Test
public void testString0() {
    SpreadsheetBooleanAdapter adapter = new SpreadsheetBooleanAdapter();

    Cell cell = mock(Cell.class);
    when(cell.getCellType()).thenReturn(Cell.CELL_TYPE_STRING);
    when(cell.getRichStringCellValue()).thenReturn(new HSSFRichTextString("0"));

    Boolean value = adapter.fromSpreadsheet(cell);
    Assert.assertFalse(value);/*w ww  . ja  v  a2  s  .c  o  m*/
}

From source file:midas.sheeco.type.adapter.SpreadsheetBooleanAdapterTest.java

License:Apache License

@Test(expected = InvalidCellValueException.class)
public void testInvalidString() {
    SpreadsheetBooleanAdapter adapter = new SpreadsheetBooleanAdapter();

    Cell cell = mock(Cell.class);
    when(cell.getCellType()).thenReturn(Cell.CELL_TYPE_STRING);
    when(cell.getRichStringCellValue()).thenReturn(new HSSFRichTextString("Vida"));

    adapter.fromSpreadsheet(cell);// w  w w .  jav  a2 s .  com
}

From source file:midas.sheeco.type.adapter.SpreadsheetBooleanAdapterTest.java

License:Apache License

@Test(expected = InvalidCellFormatException.class)
public void testInvalidError() {
    SpreadsheetBooleanAdapter adapter = new SpreadsheetBooleanAdapter();

    Cell cell = mock(Cell.class);
    when(cell.getCellType()).thenReturn(Cell.CELL_TYPE_ERROR);
    when(cell.getRichStringCellValue()).thenReturn(new HSSFRichTextString("Vida"));

    adapter.fromSpreadsheet(cell);/*ww w . j  av a  2s  .c  o m*/
}

From source file:midas.sheeco.type.adapter.SpreadsheetBooleanAdapterTest.java

License:Apache License

@Test(expected = InvalidCellFormatException.class)
public void testInvalidFormula() {
    SpreadsheetBooleanAdapter adapter = new SpreadsheetBooleanAdapter();

    Cell cell = mock(Cell.class);
    when(cell.getCellType()).thenReturn(Cell.CELL_TYPE_FORMULA);
    when(cell.getRichStringCellValue()).thenReturn(new HSSFRichTextString("Vida"));

    adapter.fromSpreadsheet(cell);/*from  w ww  .ja v  a 2  s  .co m*/
}

From source file:midas.sheeco.type.adapter.SpreadsheetDateAdapterTest.java

License:Apache License

@Test(expected = InvalidCellFormatException.class)
public void testInvalidError() {

    Cell cell = mock(Cell.class);
    when(cell.getCellType()).thenReturn(Cell.CELL_TYPE_ERROR);
    when(cell.getRichStringCellValue()).thenReturn(new HSSFRichTextString("Vida"));

    adapter.fromSpreadsheet(cell);//w  w  w  .ja v  a2  s.  c  om
}

From source file:midas.sheeco.type.adapter.SpreadsheetDateAdapterTest.java

License:Apache License

@Test(expected = InvalidCellFormatException.class)
public void testInvalidFormula() {

    Cell cell = mock(Cell.class);
    when(cell.getCellType()).thenReturn(Cell.CELL_TYPE_FORMULA);
    when(cell.getRichStringCellValue()).thenReturn(new HSSFRichTextString("Vida"));

    adapter.fromSpreadsheet(cell);/*from  ww  w. jav a  2  s  .  c o m*/
}

From source file:misuExcel.excelAdd.java

License:Open Source License

private String getCellString(Cell cell) {
    try {//from   w  ww.j ava 2 s.c o m
        switch (cell.getCellType()) {
        case Cell.CELL_TYPE_STRING:
            return cell.getRichStringCellValue().getString().trim();
        case Cell.CELL_TYPE_NUMERIC:
            if (DateUtil.isCellDateFormatted(cell)) {
                return cell.getDateCellValue().toString().trim();
            } else {
                return String.valueOf(cell.getNumericCellValue()).trim();
            }
        case Cell.CELL_TYPE_BOOLEAN:
            return String.valueOf(cell.getBooleanCellValue()).trim();
        case Cell.CELL_TYPE_FORMULA:
            return String.valueOf(cell.getCellFormula()).trim();
        default:
            return cell.getRichStringCellValue().getString().trim();
        }
    } catch (NullPointerException e) {
        JOptionPane.showMessageDialog(null, e.getMessage(), "", JOptionPane.ERROR_MESSAGE);
    }
    return null;
}

From source file:misuExcel.excelSplit.java

License:Open Source License

private String getCellString(Cell cell) {
    try {/*from  w w w  .j a va2s. com*/
        switch (cell.getCellType()) {
        case Cell.CELL_TYPE_STRING:
            return cell.getRichStringCellValue().getString().trim();
        case Cell.CELL_TYPE_NUMERIC:
            if (DateUtil.isCellDateFormatted(cell)) {
                return cell.getDateCellValue().toString().trim();
            } else {
                return String.valueOf(cell.getNumericCellValue()).trim();
            }
        case Cell.CELL_TYPE_BOOLEAN:
            return String.valueOf(cell.getBooleanCellValue()).trim();
        case Cell.CELL_TYPE_FORMULA:
            return String.valueOf(cell.getCellFormula()).trim();
        default:
            return cell.getStringCellValue().trim();
        }
    } catch (NullPointerException e) {
        JOptionPane.showMessageDialog(null, e.getMessage(), "", JOptionPane.ERROR_MESSAGE);
    }
    return null;
}

From source file:misuExcel.excelWrite.java

License:Open Source License

private void outType01() {
    if (wbSheet != null && names != null && list != null) {
        Log.info("list size:" + list.size());
        String strinfo = "";
        for (int i = 0; i < list.size(); i++) {
            ArrayList<Integer> integers = list.get(i);
            Workbook splitWb = null;//from  w w w . ja v a2 s . c o  m
            if (indexType == 1)
                splitWb = new XSSFWorkbook();
            else if (indexType == 2)
                splitWb = new HSSFWorkbook();
            Sheet sheet = splitWb.createSheet("split");
            for (int j = 0; j < integers.size() + splitJpanel.ignore_Row; j++) {
                Row row = null;
                Row copy = null;
                if (j >= splitJpanel.ignore_Row) {
                    row = sheet.createRow(j);
                    copy = wbSheet.getRow(integers.get(j - splitJpanel.ignore_Row));
                } else {
                    row = sheet.createRow(j);
                    copy = wbSheet.getRow(j);
                }
                for (int k = 0; k < copy.getLastCellNum(); k++) {
                    Cell cell = row.createCell(k);
                    Cell copyCell = copy.getCell(k);
                    if (copyCell != null) {
                        switch (copyCell.getCellType()) {
                        case Cell.CELL_TYPE_STRING:
                            cell.setCellValue(copyCell.getRichStringCellValue().getString().trim());
                            break;
                        case Cell.CELL_TYPE_NUMERIC:
                            if (DateUtil.isCellDateFormatted(copyCell)) {
                                cell.setCellValue(copyCell.getDateCellValue());
                            } else {
                                cell.setCellValue(copyCell.getNumericCellValue());
                            }
                            break;
                        case Cell.CELL_TYPE_BOOLEAN:
                            cell.setCellValue(copyCell.getBooleanCellValue());
                            break;
                        case Cell.CELL_TYPE_FORMULA:
                            cell.setCellValue(copyCell.getCellFormula());
                            break;
                        default:
                            cell.setCellValue(copyCell.getStringCellValue().trim());
                        }
                    }
                }
            }
            createWB(splitWb, names.get(i));
            Log.info(names.get(i) + ".xlsx?");
            strinfo += names.get(i) + "." + _index + "?;";
            if (i != 0 && i % 3 == 0) {
                strinfo += "\n";
            }
        } //end for
        JOptionPane.showMessageDialog(null, strinfo);
    }
}