Example usage for org.apache.poi.ss.usermodel CellStyle getBorderRight

List of usage examples for org.apache.poi.ss.usermodel CellStyle getBorderRight

Introduction

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

Prototype

BorderStyle getBorderRight();

Source Link

Document

get the type of border to use for the right border of the cell

Usage

From source file:org.pentaho.di.trans.steps.excelwriter.ExcelWriterStep_StyleFormatTest.java

License:Apache License

/**
 * Test applying Format and Style from cell (from a template) when writing fields
 *
 * @param fileType//from w  ww .  j av a2  s. c om
 * @throws Exception
 */
private void testStyleFormat(String fileType) throws Exception {
    setupStepMock(fileType);
    createStepMeta(fileType);
    createStepData(fileType);
    step.init(stepMeta, stepData);

    // We do not run transformation or executing the whole step
    // instead we just execute ExcelWriterStepData.writeNextLine() to write to Excel workbook object
    // Values are written in A2:D2 and A3:D3 rows
    List<Object[]> rows = createRowData();
    for (int i = 0; i < rows.size(); i++) {
        step.writeNextLine(rows.get(i));
    }

    // Custom styles are loaded from G1 cell
    Row xlsRow = stepData.sheet.getRow(0);
    Cell baseCell = xlsRow.getCell(6);
    CellStyle baseCellStyle = baseCell.getCellStyle();
    DataFormat format = stepData.wb.createDataFormat();

    // Check style of the exported values in A3:D3
    xlsRow = stepData.sheet.getRow(2);
    for (int i = 0; i < stepData.inputRowMeta.size(); i++) {
        Cell cell = xlsRow.getCell(i);
        CellStyle cellStyle = cell.getCellStyle();

        if (i > 0) {
            assertEquals(cellStyle.getBorderRight(), baseCellStyle.getBorderRight());
            assertEquals(cellStyle.getFillPattern(), baseCellStyle.getFillPattern());
        } else {
            // cell A2/A3 has no custom style
            assertFalse(cellStyle.getBorderRight() == baseCellStyle.getBorderRight());
            assertFalse(cellStyle.getFillPattern() == baseCellStyle.getFillPattern());
        }

        if (i != 1) {
            assertEquals(format.getFormat(cellStyle.getDataFormat()), "0.00000");
        } else {
            // cell B2/B3 use different format from the custom style
            assertEquals(format.getFormat(cellStyle.getDataFormat()), "##0,000.0");
        }
    }
}

From source file:ru.icc.cells.ssdc.DataLoader.java

License:Apache License

private void fillCellStyle(CStyle cellStyle, CellStyle excelCellStyle) {
    Font excelFont = workbook.getFontAt(excelCellStyle.getFontIndex());
    // TODO    CFont newFont(excelFont)
    //CFont font = new CFont();
    //cellStyle.setFont( font );
    CFont font = cellStyle.getFont();//from  w w w  . j  av a 2 s.  co  m

    fillFont(font, excelFont);

    cellStyle.setHidden(excelCellStyle.getHidden());
    cellStyle.setLocked(excelCellStyle.getLocked());
    cellStyle.setWrapped(excelCellStyle.getWrapText());

    cellStyle.setIndention(excelCellStyle.getIndention());
    cellStyle.setRotation(excelCellStyle.getRotation());

    cellStyle.setHorzAlignment(this.getHorzAlignment(excelCellStyle.getAlignment()));
    cellStyle.setVertAlignment(this.getVertAlignment(excelCellStyle.getVerticalAlignment()));

    CBorder leftBorder = cellStyle.getLeftBorder();
    CBorder rightBorder = cellStyle.getRightBorder();
    CBorder topBorder = cellStyle.getTopBorder();
    CBorder bottomBorder = cellStyle.getBottomBorder();

    BorderType lbType = this.convertBorderType(excelCellStyle.getBorderLeft());
    BorderType rbType = this.convertBorderType(excelCellStyle.getBorderRight());
    BorderType tbType = this.convertBorderType(excelCellStyle.getBorderTop());
    BorderType bbType = this.convertBorderType(excelCellStyle.getBorderBottom());

    leftBorder.setType(lbType);
    rightBorder.setType(rbType);
    topBorder.setType(tbType);
    bottomBorder.setType(bbType);

    //   "Fill Background Color" ???,    ??,
    //   ? ??? .  ?  .
    //      "Fill Foreground Color"
    XSSFColor bgColor = (XSSFColor) excelCellStyle.getFillBackgroundColorColor();

    // ? Index   64,  ? ,         ,
    // ?  ?   null ? 
    if (null != bgColor && 64 != bgColor.getIndexed()) {
        String bgColorHexRGB = bgColor.getARGBHex().substring(2);
        cellStyle.setBgColor(new CColor(bgColorHexRGB));
    }

    //   "Fill Background Color"      ??,
    //   ? ??? .      
    XSSFColor fgColor = (XSSFColor) excelCellStyle.getFillForegroundColorColor();

    if (null != fgColor && 64 != fgColor.getIndexed()) {
        String fgColorHexRGB = fgColor.getARGBHex().substring(2);
        cellStyle.setFgColor(new CColor(fgColorHexRGB));
    }

    // TODO   
}

From source file:ru.spb.nicetu.tableviewer.server.XlsToHtml.java

License:Apache License

private void borderStyles(CellStyle style, Formatter out, boolean isBuiltIn) {
    styleOut("border-left", style.getBorderLeft(), BORDER, out, isBuiltIn);
    styleOut("border-right", style.getBorderRight(), BORDER, out, isBuiltIn);
    styleOut("border-top", style.getBorderTop(), BORDER, out, isBuiltIn);
    styleOut("border-bottom", style.getBorderBottom(), BORDER, out, isBuiltIn);
}

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.
 *///ww  w. j  av  a  2s .  com
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());
    }
}