Example usage for org.apache.poi.hssf.usermodel HSSFFont getFontHeight

List of usage examples for org.apache.poi.hssf.usermodel HSSFFont getFontHeight

Introduction

In this page you can find the example usage for org.apache.poi.hssf.usermodel HSSFFont 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:com.eryansky.core.excelTools.ExcelUtils.java

License:Apache License

public static String dumpFont(HSSFFont font) {
    StringBuffer sb = new StringBuffer();
    sb.append(font.getItalic()).append(",").append(font.getStrikeout()).append(",").append(font.getBoldweight())
            .append(",").append(font.getCharSet()).append(",").append(font.getColor()).append(",")
            .append(font.getFontHeight()).append(",").append(font.getFontName()).append(",")
            .append(font.getTypeOffset()).append(",").append(font.getUnderline());
    return sb.toString();
}

From source file:com.eryansky.core.excelTools.ExcelUtils.java

License:Apache License

public static HSSFCellStyle findStyle(HSSFCellStyle style, HSSFWorkbook srcwb, HSSFWorkbook destwb) {
    HSSFPalette srcpalette = srcwb.getCustomPalette();
    HSSFPalette destpalette = destwb.getCustomPalette();

    for (short i = 0; i < destwb.getNumCellStyles(); i++) {
        HSSFCellStyle old = destwb.getCellStyleAt(i);
        if (old == null)
            continue;

        if (style.getAlignment() == old.getAlignment() && style.getBorderBottom() == old.getBorderBottom()
                && style.getBorderLeft() == old.getBorderLeft()
                && style.getBorderRight() == old.getBorderRight() && style.getBorderTop() == old.getBorderTop()
                && isSameColor(style.getBottomBorderColor(), old.getBottomBorderColor(), srcpalette,
                        destpalette)//w  ww.ja  v a2 s  .  c  om
                && style.getDataFormat() == old.getDataFormat()
                && isSameColor(style.getFillBackgroundColor(), old.getFillBackgroundColor(), srcpalette,
                        destpalette)
                && isSameColor(style.getFillForegroundColor(), old.getFillForegroundColor(), srcpalette,
                        destpalette)
                && style.getFillPattern() == old.getFillPattern() && style.getHidden() == old.getHidden()
                && style.getIndention() == old.getIndention()
                && isSameColor(style.getLeftBorderColor(), old.getLeftBorderColor(), srcpalette, destpalette)
                && style.getLocked() == old.getLocked()
                && isSameColor(style.getRightBorderColor(), old.getRightBorderColor(), srcpalette, destpalette)
                && style.getRotation() == old.getRotation()
                && isSameColor(style.getTopBorderColor(), old.getTopBorderColor(), srcpalette, destpalette)
                && style.getVerticalAlignment() == old.getVerticalAlignment()
                && style.getWrapText() == old.getWrapText()) {

            HSSFFont oldfont = destwb.getFontAt(old.getFontIndex());
            HSSFFont font = srcwb.getFontAt(style.getFontIndex());
            if (oldfont.getBoldweight() == font.getBoldweight() && oldfont.getItalic() == font.getItalic()
                    && oldfont.getStrikeout() == font.getStrikeout()
                    && oldfont.getCharSet() == font.getCharSet()
                    && isSameColor(oldfont.getColor(), font.getColor(), srcpalette, destpalette)
                    && oldfont.getFontHeight() == font.getFontHeight()
                    && oldfont.getFontName().equals(font.getFontName())
                    && oldfont.getTypeOffset() == font.getTypeOffset()
                    && oldfont.getUnderline() == font.getUnderline()) {
                return old;
            }
        }
    }
    return null;
}

From source file:com.eryansky.core.excelTools.ExcelUtils.java

License:Apache License

public static void copyCellStyle(HSSFWorkbook destwb, HSSFCellStyle dest, HSSFWorkbook srcwb,
        HSSFCellStyle src) {/*from  w ww .j  a v a 2  s.c om*/
    if (src == null || dest == null)
        return;
    dest.setAlignment(src.getAlignment());
    dest.setBorderBottom(src.getBorderBottom());
    dest.setBorderLeft(src.getBorderLeft());
    dest.setBorderRight(src.getBorderRight());
    dest.setBorderTop(src.getBorderTop());
    dest.setBottomBorderColor(findColor(src.getBottomBorderColor(), srcwb, destwb));
    dest.setDataFormat(
            destwb.createDataFormat().getFormat(srcwb.createDataFormat().getFormat(src.getDataFormat())));
    dest.setFillPattern(src.getFillPattern());
    dest.setFillForegroundColor(findColor(src.getFillForegroundColor(), srcwb, destwb));
    dest.setFillBackgroundColor(findColor(src.getFillBackgroundColor(), srcwb, destwb));
    dest.setHidden(src.getHidden());
    dest.setIndention(src.getIndention());
    dest.setLeftBorderColor(findColor(src.getLeftBorderColor(), srcwb, destwb));
    dest.setLocked(src.getLocked());
    dest.setRightBorderColor(findColor(src.getRightBorderColor(), srcwb, destwb));
    dest.setRotation(src.getRotation());
    dest.setTopBorderColor(findColor(src.getTopBorderColor(), srcwb, destwb));
    dest.setVerticalAlignment(src.getVerticalAlignment());
    dest.setWrapText(src.getWrapText());

    HSSFFont f = srcwb.getFontAt(src.getFontIndex());
    HSSFFont nf = findFont(f, srcwb, destwb);
    if (nf == null) {
        nf = destwb.createFont();
        nf.setBoldweight(f.getBoldweight());
        nf.setCharSet(f.getCharSet());
        nf.setColor(findColor(f.getColor(), srcwb, destwb));
        nf.setFontHeight(f.getFontHeight());
        nf.setFontHeightInPoints(f.getFontHeightInPoints());
        nf.setFontName(f.getFontName());
        nf.setItalic(f.getItalic());
        nf.setStrikeout(f.getStrikeout());
        nf.setTypeOffset(f.getTypeOffset());
        nf.setUnderline(f.getUnderline());
    }
    dest.setFont(nf);
}

From source file:com.eryansky.core.excelTools.ExcelUtils.java

License:Apache License

private static HSSFFont findFont(HSSFFont font, HSSFWorkbook src, HSSFWorkbook dest) {
    for (short i = 0; i < dest.getNumberOfFonts(); i++) {
        HSSFFont oldfont = dest.getFontAt(i);
        if (font.getBoldweight() == oldfont.getBoldweight() && font.getItalic() == oldfont.getItalic()
                && font.getStrikeout() == oldfont.getStrikeout() && font.getCharSet() == oldfont.getCharSet()
                && font.getColor() == oldfont.getColor() && font.getFontHeight() == oldfont.getFontHeight()
                && font.getFontName().equals(oldfont.getFontName())
                && font.getTypeOffset() == oldfont.getTypeOffset()
                && font.getUnderline() == oldfont.getUnderline()) {
            return oldfont;
        }/*from   w  w  w .ja  v  a2 s .  c om*/
    }
    return null;
}

From source file:com.haulmont.yarg.formatters.impl.xls.hints.CustomCellStyleHint.java

License:Apache License

@Override
public void apply() {
    for (DataObject dataObject : data) {
        HSSFCell templateCell = dataObject.templateCell;
        HSSFCell resultCell = dataObject.resultCell;
        BandData bandData = dataObject.bandData;

        HSSFWorkbook resultWorkbook = resultCell.getSheet().getWorkbook();
        HSSFWorkbook templateWorkbook = templateCell.getSheet().getWorkbook();

        String templateCellValue = templateCell.getStringCellValue();

        Matcher matcher = pattern.matcher(templateCellValue);
        if (matcher.find()) {
            String paramName = matcher.group(1);
            String styleName = (String) bandData.getParameterValue(paramName);
            if (styleName == null)
                continue;

            HSSFCellStyle cellStyle = styleCache.getStyleByName(styleName);
            if (cellStyle == null)
                continue;

            HSSFCellStyle resultStyle = styleCache.getNamedCachedStyle(cellStyle);

            if (resultStyle == null) {
                HSSFCellStyle newStyle = resultWorkbook.createCellStyle();
                // color
                newStyle.setFillBackgroundColor(cellStyle.getFillBackgroundColor());
                newStyle.setFillForegroundColor(cellStyle.getFillForegroundColor());
                newStyle.setFillPattern(cellStyle.getFillPattern());

                // borders
                newStyle.setBorderLeft(cellStyle.getBorderLeft());
                newStyle.setBorderRight(cellStyle.getBorderRight());
                newStyle.setBorderTop(cellStyle.getBorderTop());
                newStyle.setBorderBottom(cellStyle.getBorderBottom());

                // border colors
                newStyle.setLeftBorderColor(cellStyle.getLeftBorderColor());
                newStyle.setRightBorderColor(cellStyle.getRightBorderColor());
                newStyle.setBottomBorderColor(cellStyle.getBottomBorderColor());
                newStyle.setTopBorderColor(cellStyle.getTopBorderColor());

                // alignment
                newStyle.setAlignment(cellStyle.getAlignment());
                newStyle.setVerticalAlignment(cellStyle.getVerticalAlignment());
                // misc
                DataFormat dataFormat = resultWorkbook.getCreationHelper().createDataFormat();
                newStyle.setDataFormat(dataFormat.getFormat(cellStyle.getDataFormatString()));
                newStyle.setHidden(cellStyle.getHidden());
                newStyle.setLocked(cellStyle.getLocked());
                newStyle.setIndention(cellStyle.getIndention());
                newStyle.setRotation(cellStyle.getRotation());
                newStyle.setWrapText(cellStyle.getWrapText());
                // font
                HSSFFont cellFont = cellStyle.getFont(templateWorkbook);
                HSSFFont newFont = fontCache.getFontByTemplate(cellFont);

                if (newFont == null) {
                    newFont = resultWorkbook.createFont();

                    newFont.setFontName(cellFont.getFontName());
                    newFont.setItalic(cellFont.getItalic());
                    newFont.setStrikeout(cellFont.getStrikeout());
                    newFont.setTypeOffset(cellFont.getTypeOffset());
                    newFont.setBoldweight(cellFont.getBoldweight());
                    newFont.setCharSet(cellFont.getCharSet());
                    newFont.setColor(cellFont.getColor());
                    newFont.setUnderline(cellFont.getUnderline());
                    newFont.setFontHeight(cellFont.getFontHeight());
                    newFont.setFontHeightInPoints(cellFont.getFontHeightInPoints());
                    fontCache.addCachedFont(cellFont, newFont);
                }/* w  ww. j av  a2 s. co m*/
                newStyle.setFont(newFont);

                resultStyle = newStyle;
                styleCache.addCachedNamedStyle(cellStyle, resultStyle);
            }

            fixNeighbourCellBorders(cellStyle, resultCell);

            resultCell.setCellStyle(resultStyle);

            Sheet sheet = resultCell.getSheet();
            for (int i = 0; i < sheet.getNumMergedRegions(); i++) {
                CellRangeAddress mergedRegion = sheet.getMergedRegion(i);
                if (mergedRegion.isInRange(resultCell.getRowIndex(), resultCell.getColumnIndex())) {

                    int firstRow = mergedRegion.getFirstRow();
                    int lastRow = mergedRegion.getLastRow();
                    int firstCol = mergedRegion.getFirstColumn();
                    int lastCol = mergedRegion.getLastColumn();

                    for (int row = firstRow; row <= lastRow; row++)
                        for (int col = firstCol; col <= lastCol; col++)
                            sheet.getRow(row).getCell(col).setCellStyle(resultStyle);

                    // cell includes only in one merged region
                    break;
                }
            }
        }
    }
}

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

License:Apache License

/**
 * [Flow #-6]  ?  :  ? ?(?, ? )? /*ww w.  j  a  va2s  .c om*/
 */
@Test
public void testModifyCellAttribute() throws Exception {

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

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

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

            log.debug("Delete file...." + sb.toString());
        }

        HSSFWorkbook wbTmp = new HSSFWorkbook();
        wbTmp.createSheet();

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

        //  ? 
        HSSFWorkbook wb = excelService.loadWorkbook(sb.toString());
        log.debug("testModifyCellAttribute after loadWorkbook....");

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

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

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

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

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

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

        //////////////////////////////////////////////////////////////////////////
        // ?
        HSSFWorkbook wbT = excelService.loadWorkbook(sb.toString());
        HSSFSheet sheetT = wbT.getSheet("cell test sheet2");
        log.debug("getNumCellStyles : " + wbT.getNumCellStyles());

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

        HSSFFont fontT = cs1.getFont(wbT);
        log.debug("font getFontHeight : " + fontT.getFontHeight());
        log.debug("font getBoldweight : " + fontT.getBoldweight());
        log.debug("font getFontName : " + fontT.getFontName());
        log.debug("getAlignment : " + cs1.getAlignment());
        log.debug("getWrapText : " + cs1.getWrapText());

        for (int i = 0; i < 100; i++) {
            HSSFRow row1 = sheetT.getRow(i);
            for (int j = 0; j < 5; j++) {
                HSSFCell cell1 = row1.getCell(j);
                log.debug("row " + i + ", cell " + j + " : " + cell1.getRichStringCellValue());
                assertEquals(16, fontT.getFontHeight());
                assertEquals(3, fontT.getBoldweight());
                assertEquals(HSSFCellStyle.ALIGN_RIGHT, cs1.getAlignment());
                assertTrue(cs1.getWrapText());
            }
        }

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

From source file:fitlibrary.runner.SpreadsheetRunner.java

License:Open Source License

private String format(HSSFCell cell, HSSFWorkbook workbook) {
    if (cell == null)
        return "";
    String value = value(cell);/* w  ww  . j  a v a2 s .c om*/
    HSSFCellStyle style = cell.getCellStyle();
    HSSFFont font = workbook.getFontAt(style.getFontIndex());
    // System.err.println("Formatting "+value(cell)+"= "+font.getFontHeight());
    if (font.getItalic())
        value = tag("i", value);
    if (font.getBoldweight() > 400)
        value = tag("b", value);
    if (font.getUnderline() > 0)
        value = tag("u", value);
    if (font.getFontHeight() >= 480)
        value = tag("h1", value);
    else if (font.getFontHeight() >= 280)
        value = tag("h2", value);
    else if (font.getFontHeight() > 200)
        value = tag("h3", value);
    return value;
}

From source file:org.bbreak.excella.core.test.util.TestUtil.java

License:Open Source License

private static String getHSSFFontString(HSSFWorkbook workbook, HSSFFont font) {
    StringBuffer sb = new StringBuffer();
    sb.append("[FONT]");
    sb.append("fontheight=").append(Integer.toHexString(font.getFontHeight())).append(",");
    sb.append("italic=").append(font.getItalic()).append(",");
    sb.append("strikout=").append(font.getStrikeout()).append(",");
    sb.append("colorpalette=").append(getHSSFColorString((HSSFWorkbook) workbook, font.getColor())).append(",");
    sb.append("boldweight=").append(font.getBold()).append(",");
    sb.append("supersubscript=").append(Integer.toHexString(font.getTypeOffset())).append(",");
    sb.append("underline=").append(Integer.toHexString(font.getUnderline())).append(",");
    sb.append("charset=").append(Integer.toHexString(font.getCharSet())).append(",");
    sb.append("fontname=").append(font.getFontName());
    sb.append("[/FONT]");
    return sb.toString();
}

From source file:org.bbreak.excella.reports.ReportsTestUtil.java

License:Open Source License

/**
 * HSSF????//from w  ww  . ja  va  2s.  co m
 * 
 * @param workbook 
 * @param font 
 * @return ??
 */
private static String getHSSFFontString(HSSFWorkbook workbook, HSSFFont font) {
    StringBuffer sb = new StringBuffer();
    sb.append("[FONT]");
    sb.append("fontheight=").append(Integer.toHexString(font.getFontHeight())).append(",");
    sb.append("italic=").append(font.getItalic()).append(",");
    sb.append("strikout=").append(font.getStrikeout()).append(",");
    sb.append("colorpalette=").append(getHSSFColorString((HSSFWorkbook) workbook, font.getColor())).append(",");
    sb.append("bold=").append(font.getBold()).append(",");
    sb.append("supersubscript=").append(Integer.toHexString(font.getTypeOffset())).append(",");
    sb.append("underline=").append(Integer.toHexString(font.getUnderline())).append(",");
    sb.append("charset=").append(Integer.toHexString(font.getCharSet())).append(",");
    sb.append("fontname=").append(font.getFontName());
    sb.append("[/FONT]");
    return sb.toString();
}

From source file:org.orbeon.oxf.util.XLSUtils.java

License:Open Source License

public static void copyFont(HSSFFont destination, HSSFFont source) {
    destination.setBoldweight(source.getBoldweight());
    destination.setColor(source.getColor());
    destination.setFontHeight(source.getFontHeight());
    destination.setFontHeightInPoints(source.getFontHeightInPoints());
    destination.setFontName(source.getFontName());
    destination.setItalic(source.getItalic());
    destination.setStrikeout(source.getStrikeout());
    destination.setTypeOffset(source.getTypeOffset());
    destination.setUnderline(source.getUnderline());
}