Example usage for org.apache.poi.xssf.usermodel XSSFFont getFontHeight

List of usage examples for org.apache.poi.xssf.usermodel XSSFFont getFontHeight

Introduction

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

Prototype

public short getFontHeight() 

Source Link

Document

Get the font height in unit's of 1/20th of a point.

Usage

From source file:egovframework.rte.fdl.excel.EgovExcelXSSFServiceTest.java

License:Apache License

/**
 * [Flow #-6]  ?  :  ? ?(?, ? )? //  w  w w . j  ava 2s  . c o m
 */
@Test
public void testModifyCellAttribute() throws Exception {

    try {
        LOGGER.debug("testModifyCellAttribute start....");

        StringBuffer sb = new StringBuffer();
        sb.append(fileLocation).append("/").append("testModifyCellAttribute.xlsx");

        if (EgovFileUtil.isExistsFile(sb.toString())) {
            EgovFileUtil.delete(new File(sb.toString()));

            LOGGER.debug("Delete file....{}", sb.toString());
        }

        Workbook wbTmp = new XSSFWorkbook();
        wbTmp.createSheet();

        //  ? ?
        excelService.createWorkbook(wbTmp, sb.toString());

        //  ? 
        XSSFWorkbook wb = excelService.loadWorkbook(sb.toString(), new XSSFWorkbook());
        LOGGER.debug("testModifyCellAttribute after loadWorkbook....");

        Sheet sheet = wb.createSheet("cell test sheet2");
        sheet.setColumnWidth((short) 3, (short) 200); // column Width

        CellStyle cs = wb.createCellStyle();
        XSSFFont font = wb.createFont();
        font.setFontHeight(16);
        font.setBoldweight((short) 3);
        font.setFontName("fixedsys");

        cs.setFont(font);
        cs.setAlignment(XSSFCellStyle.ALIGN_RIGHT); // cell 
        cs.setWrapText(true);

        for (int i = 0; i < 100; i++) {
            Row row = sheet.createRow(i);
            row.setHeight((short) 300); // row? height 

            for (int j = 0; j < 5; j++) {
                Cell cell = row.createCell(j);
                cell.setCellValue(new XSSFRichTextString("row " + i + ", cell " + j));
                cell.setCellStyle(cs);
            }
        }

        //  ? 
        FileOutputStream out = new FileOutputStream(sb.toString());
        wb.write(out);
        out.close();

        //////////////////////////////////////////////////////////////////////////
        // ?
        XSSFWorkbook wbT = excelService.loadWorkbook(sb.toString(), new XSSFWorkbook());
        Sheet sheetT = wbT.getSheet("cell test sheet2");
        LOGGER.debug("getNumCellStyles : {}", wbT.getNumCellStyles());

        XSSFCellStyle cs1 = (XSSFCellStyle) wbT.getCellStyleAt((short) (wbT.getNumCellStyles() - 1));

        XSSFFont fontT = cs1.getFont();
        LOGGER.debug("font getFontHeight : {}", fontT.getFontHeight());
        LOGGER.debug("font getBoldweight : {}", fontT.getBoldweight());
        LOGGER.debug("font getFontName : {}", fontT.getFontName());
        LOGGER.debug("getAlignment : {}", cs1.getAlignment());
        LOGGER.debug("getWrapText : {}", cs1.getWrapText());

        for (int i = 0; i < 100; i++) {
            Row row1 = sheetT.getRow(i);
            for (int j = 0; j < 5; j++) {
                Cell cell1 = row1.getCell(j);
                LOGGER.debug("row {}, cell {} : {}", i, j, cell1.getRichStringCellValue());
                assertEquals(320, fontT.getFontHeight());
                assertEquals(400, fontT.getBoldweight());
                LOGGER.debug("fontT.getBoldweight()? ? 400? ?");

                assertEquals(XSSFCellStyle.ALIGN_RIGHT, cs1.getAlignment());
                assertTrue(cs1.getWrapText());
            }
        }

    } catch (Exception e) {
        LOGGER.error(e.toString());
        throw new Exception(e);
    } finally {
        LOGGER.debug("testModifyCellAttribute end....");
    }
}

From source file:org.sysmodb.xml.XSSFXMLStyleHelper.java

License:BSD License

public boolean areFontsEmpty(CellStyle style) {
    XSSFCellStyle newStyle = (XSSFCellStyle) style;
    XSSFFont font = newStyle.getFont();
    if (font.getBold())
        return false;
    if (font.getItalic())
        return false;
    if (font.getUnderline() != XSSFFont.U_NONE)
        return false;
    if (font.getFontHeight() != XSSFFont.DEFAULT_FONT_SIZE)
        return false;
    if (!font.getFontName().equals(XSSFFont.DEFAULT_FONT_NAME))
        return false;
    if (font.getColor() != XSSFFont.DEFAULT_FONT_COLOR) {
        String colorString = getRGBString(font.getXSSFColor());
        if (colorString != null) {
            return false;
        }/* ww w.java  2s.  co m*/
    }
    return true;
}

From source file:org.sysmodb.xml.XSSFXMLStyleHelper.java

License:BSD License

@Override
public void writeFontProperties(XMLStreamWriter xmlWriter, CellStyle style) throws XMLStreamException {
    XSSFCellStyle newStyle = (XSSFCellStyle) style;
    XSSFFont font = newStyle.getFont();
    if (font.getBold()) {
        xmlWriter.writeStartElement("font-weight");
        xmlWriter.writeCharacters("bold");
        xmlWriter.writeEndElement();//w w w .  j a  va2s. c  o m
    }
    if (font.getItalic()) {
        xmlWriter.writeStartElement("font-style");
        xmlWriter.writeCharacters("italics");
        xmlWriter.writeEndElement();
    }
    if (font.getUnderline() != XSSFFont.U_NONE) {
        xmlWriter.writeStartElement("text-decoration");
        xmlWriter.writeCharacters("underline");
        xmlWriter.writeEndElement();
    }
    if (font.getFontHeight() != XSSFFont.DEFAULT_FONT_SIZE) {
        xmlWriter.writeStartElement("font-size");
        xmlWriter.writeCharacters(String.valueOf(font.getFontHeightInPoints()) + "pt");
        xmlWriter.writeEndElement();
    }

    if (!font.getFontName().equals(XSSFFont.DEFAULT_FONT_NAME)) {
        xmlWriter.writeStartElement("font-family");
        xmlWriter.writeCharacters(String.valueOf(font.getFontName()));
        xmlWriter.writeEndElement();
    }
    if (font.getColor() != XSSFFont.DEFAULT_FONT_COLOR) {
        String colorString = getRGBString(font.getXSSFColor());
        if (colorString != null) {
            xmlWriter.writeStartElement("color");
            xmlWriter.writeCharacters(colorString);
            xmlWriter.writeEndElement();
        }
    }

}