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

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

Introduction

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

Prototype

CellStyle getCellStyle();

Source Link

Document

Return the cell's style.

Usage

From source file:uk.co.spudsoft.birt.emitters.excel.tests.Borders1ReportTest.java

License:Open Source License

private void assertBorder(Sheet sheet, int row, int col, short bottom, short left, short right, short top) {

    Cell cell = sheet.getRow(row).getCell(col);
    CellStyle style = cell.getCellStyle();

    assertSingleBorder(sheet, row, "bottom", bottom, style.getBorderBottom());
    assertSingleBorder(sheet, row, "left", left, style.getBorderLeft());
    assertSingleBorder(sheet, row, "right", right, style.getBorderRight());
    assertSingleBorder(sheet, row, "top", top, style.getBorderTop());
}

From source file:uk.co.spudsoft.birt.emitters.excel.tests.Borders2ReportTest.java

License:Open Source License

/**
 * Check that the borders for a given cell match the expected values.
 * This is complicated by the fact that POI will not always give a particular cell the borders that are seen in Excel
 * - neighbouring cells may override the values for the chosen cell.
 * I don't know how to tell which takes precedence, but the following works for the tests I've carried out.
 *///from  ww  w .j a v  a  2  s  .  c o  m
public static void assertBorder(Sheet sheet, int row, int col, short bottom, short left, short right,
        short top) {

    Row curRow = sheet.getRow(row);
    Row prevRow = (row > 0) ? sheet.getRow(row - 1) : null;
    Row nextRow = sheet.getRow(row + 1);
    Cell cell = curRow.getCell(col);
    CellStyle style = cell.getCellStyle();

    Cell cellUp = (prevRow == null) ? null : prevRow.getCell(col);
    Cell cellDown = (nextRow == null) ? null : nextRow.getCell(col);
    Cell cellLeft = (col == 0) ? null : curRow.getCell(col - 1);
    Cell cellRight = curRow.getCell(col + 1);

    CellStyle styleUp = (cellUp == null) ? null : cellUp.getCellStyle();
    CellStyle styleDown = (cellDown == null) ? null : cellDown.getCellStyle();
    CellStyle styleLeft = (cellLeft == null) ? null : cellLeft.getCellStyle();
    CellStyle styleRight = (cellRight == null) ? null : cellRight.getCellStyle();

    System.out.println("style == " + style);
    System.out.println("style == " + style);

    if ((top != style.getBorderTop()) && ((styleUp == null) || (top != styleUp.getBorderBottom()))) {
        assertEquals(top, style.getBorderTop());
    }
    if ((bottom != style.getBorderBottom()) && ((styleDown == null) || (bottom != styleDown.getBorderTop()))) {
        assertEquals(bottom, style.getBorderBottom());
    }
    if ((left != style.getBorderLeft()) && ((styleLeft == null) || (left != styleLeft.getBorderRight()))) {
        assertEquals(left, style.getBorderLeft());
    }
    if ((right != style.getBorderRight()) && ((styleRight == null) || (right != styleRight.getBorderLeft()))) {
        assertEquals(right, style.getBorderRight());
    }
}

From source file:uk.co.spudsoft.birt.emitters.excel.tests.FontsReportTest.java

License:Open Source License

private void assertFontCell(Sheet sheet, int row, int col, String contents, String fontName, int fontHeight) {

    Cell cell = sheet.getRow(row).getCell(col);
    CellStyle style = cell.getCellStyle();

    assertEquals(contents, cell.getStringCellValue());
    assertEquals(fontName, sheet.getWorkbook().getFontAt(style.getFontIndex()).getFontName().replace("\"", ""));
    assertEquals(fontHeight, sheet.getWorkbook().getFontAt(style.getFontIndex()).getFontHeightInPoints());
}

From source file:uk.co.spudsoft.birt.emitters.excel.tests.Issue29.java

License:Open Source License

@Test
public void testMultiRowEmptinessXlsx() throws BirtException, IOException {

    debug = false;//from www . j ava  2  s  .co  m
    InputStream inputStream = runAndRenderReport("Issue29.rptdesign", "xlsx");
    assertNotNull(inputStream);
    try {
        XSSFWorkbook workbook = new XSSFWorkbook(inputStream);
        assertNotNull(workbook);

        assertEquals(1, workbook.getNumberOfSheets());

        Sheet sheet = workbook.getSheetAt(0);
        assertEquals(6, this.firstNullRow(sheet));

        for (int i = 0; i < 4; ++i) {
            for (Cell cell : sheet.getRow(i)) {
                assertEquals(0, cell.getCellStyle().getBorderTop());
                assertEquals(0, cell.getCellStyle().getBorderLeft());
                assertEquals(0, cell.getCellStyle().getBorderRight());
                assertEquals(0, cell.getCellStyle().getBorderBottom());
            }
        }
        assertEquals("Bibble", sheet.getRow(5).getCell(0).getStringCellValue());
        assertEquals(24.0, sheet.getRow(0).getHeightInPoints(), 0.1);

    } finally {
        inputStream.close();
    }
}

From source file:uk.co.spudsoft.birt.emitters.excel.tests.Issue29.java

License:Open Source License

@Test
public void testMultiRowEmptinessXls() throws BirtException, IOException {

    debug = false;/*  w w w. java  2  s  .c om*/
    InputStream inputStream = runAndRenderReport("Issue29.rptdesign", "xls");
    assertNotNull(inputStream);
    try {
        HSSFWorkbook workbook = new HSSFWorkbook(inputStream);
        assertNotNull(workbook);

        assertEquals(1, workbook.getNumberOfSheets());

        Sheet sheet = workbook.getSheetAt(0);
        assertEquals(6, this.firstNullRow(sheet));

        for (int i = 0; i < 4; ++i) {
            for (Cell cell : sheet.getRow(i)) {
                assertEquals(0, cell.getCellStyle().getBorderTop());
                assertEquals(0, cell.getCellStyle().getBorderLeft());
                assertEquals(0, cell.getCellStyle().getBorderRight());
                assertEquals(0, cell.getCellStyle().getBorderBottom());
            }
        }
        assertEquals("Bibble", sheet.getRow(5).getCell(0).getStringCellValue());
        assertEquals(24.0, sheet.getRow(0).getHeightInPoints(), 0.1);

    } finally {
        inputStream.close();
    }
}

From source file:uk.co.spudsoft.birt.emitters.excel.tests.Issue64HungarianDates.java

License:Open Source License

@Test
public void testThreeTablesNoNastinessPdfCheck() throws BirtException, IOException {

    InputStream inputStream = new FileInputStream(deriveFilepath("formatted_date_office2010_hungarian.xls"));
    try {/*w  w  w  .  j  a  va 2s  . c  o m*/
        HSSFWorkbook workbook = new HSSFWorkbook(inputStream);
        Cell cell = workbook.getSheetAt(0).getRow(0).getCell(0);
        System.out.println("Data format string = " + cell.getCellStyle().getDataFormatString());
    } finally {
        inputStream.close();
    }
}

From source file:utilities.DMPORosterToMapGenerator.java

public DMPORosterToMapGenerator(String xlsxFileName) throws FileNotFoundException, IOException {
    db = new TreeMap();
    File myFile = new File(xlsxFileName);

    FileInputStream fis = new FileInputStream(myFile);

    System.out.println(xlsxFileName);
    XSSFWorkbook myWorkBook = new XSSFWorkbook(fis);

    XSSFSheet mySheet = myWorkBook.getSheetAt(0);
    Iterator<Row> rowIterator = mySheet.iterator();
    DataFormatter df = new DataFormatter();
    //        System.out.println(IndexedColors.YELLOW);
    //        System.out.println(IndexedColors.BLUE.getIndex());
    //        System.out.println(IndexedColors.RED.getIndex());
    //        System.out.println(IndexedColors.WHITE);
    //        System.out.println(IndexedColors.BLACK);
    //        System.out.println(IndexedColors.GREEN);

    rowIterator.next(); // skip the header row
    while (rowIterator.hasNext()) {
        Row row = rowIterator.next();//  w w w. j  a va 2  s.  c  o m
        Cell cell = row.getCell(FILE_AT_DMPO_INDX); // File at DMPO      
        int type = cell.getCellType();
        //System.out.println(cell.getStringCellValue());

        if (type == HSSFCell.CELL_TYPE_STRING && cell.getStringCellValue().equalsIgnoreCase("Yes")) { // File at DMPO      
            CellStyle style = cell.getCellStyle();

            // getFillBackgroundColor() always 64.  getFillForegroundColor() is 64 for white
            // getFillForegroundColor() is 0 for yellow
            //                System.out.println(style.getFillForegroundColor());
            //                //if (style.getFillForegroundColorColor() != null)
            //                    System.out.println(style.getFillForegroundColorColor());
            //               
            //                System.out.println(style.getFillBackgroundColor());
            //                //if (style.getFillBackgroundColorColor() != null)
            //                    System.out.println(style.getFillBackgroundColorColor());
            //if(style.getFillForegroundColor() != IndexedColors.YELLOW.getIndex()) { 
            Color color = style.getFillForegroundColorColor();
            if (color == null || color.toString().equals(GlobalVar.WHITE)) { // no fill or fill with white

                Cell ssnCell = row.getCell(SSN_INDX);
                String ssnString = df.formatCellValue(ssnCell); //return ***-**-****
                ssnString = readSSN(ssnString).trim();
                if (!db.containsKey(ssnString)) {
                    List<String> list = new LinkedList<String>();
                    String ssn = displayFormatSSN(ssnString).trim();
                    String name = row.getCell(NAME_INDX).getStringCellValue().trim();
                    String dutyStation = row.getCell(ORIGIN_INDX).getStringCellValue().trim();
                    String typeCM = row.getCell(TYPE_CM_INDX).getStringCellValue().trim();
                    //String typeCM = row.getCell(TYPE_CM_INDX).getStringCellValue();
                    list.add(ssn);
                    list.add(name);
                    list.add(dutyStation);
                    list.add(typeCM);
                    db.put(ssnString, list);
                }
            }
        }
    }
}

From source file:workbench.db.importer.ExcelReader.java

License:Apache License

private java.util.Date getDateValue(Cell cell) {
    java.util.Date dtValue = null;
    try {//from  ww w .  j  av  a 2  s  .com
        dtValue = cell.getDateCellValue();
    } catch (Exception ex) {
        // ignore
    }
    String fmt = cell.getCellStyle().getDataFormatString();
    double dv = cell.getNumericCellValue();
    if (dtValue == null) {
        dtValue = getJavaDate(dv);
    }

    if (dtValue != null) {
        if (isTimestampFormat(fmt)) {
            return new java.sql.Timestamp(dtValue.getTime());
        } else {
            return new java.sql.Date(dtValue.getTime());
        }
    }
    return null;
}