Search in sources :

Example 41 with CellStyle

use of org.apache.poi.ss.usermodel.CellStyle in project tdi-studio-se by Talend.

the class ExcelTool method getNormalCellStyle.

private CellStyle getNormalCellStyle() {
    CellStyle preCellStyle = getPreCellStyle();
    if (preCellStyle == null) {
        if (cellStylesMapping.get("normal") != null) {
            return cellStylesMapping.get("normal");
        } else {
            CellStyle style = wb.createCellStyle();
            if (font != null) {
                style.setFont(font);
            }
            cellStylesMapping.put("normal", style);
            return style;
        }
    } else {
        return preCellStyle;
    }
}
Also used : CellStyle(org.apache.poi.ss.usermodel.CellStyle)

Example 42 with CellStyle

use of org.apache.poi.ss.usermodel.CellStyle in project Robot-Scouter by SUPERCILEX.

the class SpreadsheetCache method createBaseStyle.

private CellStyle createBaseStyle() {
    CellStyle style = mWorkbook.createCellStyle();
    style.setWrapText(true);
    return style;
}
Also used : CellStyle(org.apache.poi.ss.usermodel.CellStyle)

Example 43 with CellStyle

use of org.apache.poi.ss.usermodel.CellStyle in project Robot-Scouter by SUPERCILEX.

the class SpreadsheetCache method createRowHeaderStyle.

private CellStyle createRowHeaderStyle() {
    CellStyle rowHeaderStyle = createColumnHeaderStyle();
    rowHeaderStyle.setAlignment(HorizontalAlignment.LEFT);
    return rowHeaderStyle;
}
Also used : CellStyle(org.apache.poi.ss.usermodel.CellStyle)

Example 44 with CellStyle

use of org.apache.poi.ss.usermodel.CellStyle in project poi by apache.

the class TestXSSFPropertyTemplate method clonePropertyTemplate.

@Test
public void clonePropertyTemplate() throws IOException {
    CellRangeAddress a1c3 = new CellRangeAddress(0, 2, 0, 2);
    PropertyTemplate pt = new PropertyTemplate();
    pt.drawBorders(a1c3, BorderStyle.MEDIUM, IndexedColors.RED.getIndex(), BorderExtent.ALL);
    PropertyTemplate pt2 = new PropertyTemplate(pt);
    assertNotSame(pt2, pt);
    for (int i = 0; i <= 2; i++) {
        for (int j = 0; j <= 2; j++) {
            assertEquals(4, pt2.getNumBorderColors(i, j));
            assertEquals(4, pt2.getNumBorderColors(i, j));
        }
    }
    CellRangeAddress b2 = new CellRangeAddress(1, 1, 1, 1);
    pt2.drawBorders(b2, BorderStyle.THIN, BorderExtent.ALL);
    Workbook wb = new XSSFWorkbook();
    Sheet sheet = wb.createSheet();
    pt.applyBorders(sheet);
    for (Row row : sheet) {
        for (Cell cell : row) {
            CellStyle cs = cell.getCellStyle();
            assertEquals(BorderStyle.MEDIUM, cs.getBorderTopEnum());
            assertEquals(BorderStyle.MEDIUM, cs.getBorderBottomEnum());
            assertEquals(BorderStyle.MEDIUM, cs.getBorderLeftEnum());
            assertEquals(BorderStyle.MEDIUM, cs.getBorderRightEnum());
            assertEquals(IndexedColors.RED.getIndex(), cs.getTopBorderColor());
            assertEquals(IndexedColors.RED.getIndex(), cs.getBottomBorderColor());
            assertEquals(IndexedColors.RED.getIndex(), cs.getLeftBorderColor());
            assertEquals(IndexedColors.RED.getIndex(), cs.getRightBorderColor());
        }
    }
    wb.close();
}
Also used : XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) Row(org.apache.poi.ss.usermodel.Row) CellStyle(org.apache.poi.ss.usermodel.CellStyle) Sheet(org.apache.poi.ss.usermodel.Sheet) Cell(org.apache.poi.ss.usermodel.Cell) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) Workbook(org.apache.poi.ss.usermodel.Workbook) Test(org.junit.Test)

Example 45 with CellStyle

use of org.apache.poi.ss.usermodel.CellStyle in project poi by apache.

the class TestXSSFPropertyTemplate method applyBorders.

@Test
public void applyBorders() throws IOException {
    CellRangeAddress a1c3 = new CellRangeAddress(0, 2, 0, 2);
    CellRangeAddress b2 = new CellRangeAddress(1, 1, 1, 1);
    PropertyTemplate pt = new PropertyTemplate();
    Workbook wb = new XSSFWorkbook();
    Sheet sheet = wb.createSheet();
    pt.drawBorders(a1c3, BorderStyle.THIN, IndexedColors.RED.getIndex(), BorderExtent.ALL);
    pt.applyBorders(sheet);
    for (Row row : sheet) {
        for (Cell cell : row) {
            CellStyle cs = cell.getCellStyle();
            assertEquals(BorderStyle.THIN, cs.getBorderTopEnum());
            assertEquals(IndexedColors.RED.getIndex(), cs.getTopBorderColor());
            assertEquals(BorderStyle.THIN, cs.getBorderBottomEnum());
            assertEquals(IndexedColors.RED.getIndex(), cs.getBottomBorderColor());
            assertEquals(BorderStyle.THIN, cs.getBorderLeftEnum());
            assertEquals(IndexedColors.RED.getIndex(), cs.getLeftBorderColor());
            assertEquals(BorderStyle.THIN, cs.getBorderRightEnum());
            assertEquals(IndexedColors.RED.getIndex(), cs.getRightBorderColor());
        }
    }
    pt.drawBorders(b2, BorderStyle.NONE, BorderExtent.ALL);
    pt.applyBorders(sheet);
    for (Row row : sheet) {
        for (Cell cell : row) {
            CellStyle cs = cell.getCellStyle();
            if (cell.getColumnIndex() != 1 || row.getRowNum() == 0) {
                assertEquals(BorderStyle.THIN, cs.getBorderTopEnum());
                assertEquals(IndexedColors.RED.getIndex(), cs.getTopBorderColor());
            } else {
                assertEquals(BorderStyle.NONE, cs.getBorderTopEnum());
            }
            if (cell.getColumnIndex() != 1 || row.getRowNum() == 2) {
                assertEquals(BorderStyle.THIN, cs.getBorderBottomEnum());
                assertEquals(IndexedColors.RED.getIndex(), cs.getBottomBorderColor());
            } else {
                assertEquals(BorderStyle.NONE, cs.getBorderBottomEnum());
            }
            if (cell.getColumnIndex() == 0 || row.getRowNum() != 1) {
                assertEquals(BorderStyle.THIN, cs.getBorderLeftEnum());
                assertEquals(IndexedColors.RED.getIndex(), cs.getLeftBorderColor());
            } else {
                assertEquals(BorderStyle.NONE, cs.getBorderLeftEnum());
            }
            if (cell.getColumnIndex() == 2 || row.getRowNum() != 1) {
                assertEquals(BorderStyle.THIN, cs.getBorderRightEnum());
                assertEquals(IndexedColors.RED.getIndex(), cs.getRightBorderColor());
            } else {
                assertEquals(BorderStyle.NONE, cs.getBorderRightEnum());
            }
        }
    }
    wb.close();
}
Also used : XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) Row(org.apache.poi.ss.usermodel.Row) CellStyle(org.apache.poi.ss.usermodel.CellStyle) Sheet(org.apache.poi.ss.usermodel.Sheet) Cell(org.apache.poi.ss.usermodel.Cell) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) Workbook(org.apache.poi.ss.usermodel.Workbook) Test(org.junit.Test)

Aggregations

CellStyle (org.apache.poi.ss.usermodel.CellStyle)53 Cell (org.apache.poi.ss.usermodel.Cell)31 Row (org.apache.poi.ss.usermodel.Row)27 Sheet (org.apache.poi.ss.usermodel.Sheet)26 Workbook (org.apache.poi.ss.usermodel.Workbook)25 Test (org.junit.Test)16 XSSFWorkbook (org.apache.poi.xssf.usermodel.XSSFWorkbook)14 Font (org.apache.poi.ss.usermodel.Font)13 FileOutputStream (java.io.FileOutputStream)8 HSSFWorkbook (org.apache.poi.hssf.usermodel.HSSFWorkbook)7 CreationHelper (org.apache.poi.ss.usermodel.CreationHelper)7 CellReference (org.apache.poi.ss.util.CellReference)5 Date (java.util.Date)4 DataFormat (org.apache.poi.ss.usermodel.DataFormat)4 IOException (java.io.IOException)3 DecimalFormat (java.text.DecimalFormat)3 HashMap (java.util.HashMap)3 CellType (org.apache.poi.ss.usermodel.CellType)3 File (java.io.File)2 OutputStream (java.io.OutputStream)2