Example usage for org.apache.poi.ss.usermodel Font setFontName

List of usage examples for org.apache.poi.ss.usermodel Font setFontName

Introduction

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

Prototype


void setFontName(String name);

Source Link

Document

set the name for the font (i.e.

Usage

From source file:it.eng.spagobi.engines.worksheet.exporter.WorkSheetXLSExporter.java

License:Mozilla Public License

public CellStyle buildMetadataTitleCellStyle(Sheet sheet) {
    CellStyle cellStyle = sheet.getWorkbook().createCellStyle();
    cellStyle.setAlignment(CellStyle.ALIGN_LEFT);
    cellStyle.setVerticalAlignment(CellStyle.VERTICAL_TOP);
    cellStyle.setWrapText(true);//  www . j  a  v  a2s  . c o  m
    Font font = sheet.getWorkbook().createFont();
    font.setBoldweight(Font.BOLDWEIGHT_BOLD);
    font.setFontHeightInPoints(METADATA_TITLE_FONT_SIZE);
    font.setFontName(FONT_NAME);
    cellStyle.setFont(font);
    return cellStyle;
}

From source file:it.eng.spagobi.engines.worksheet.exporter.WorkSheetXLSExporter.java

License:Mozilla Public License

public CellStyle buildMetadataNameCellStyle(Sheet sheet) {
    CellStyle cellStyle = sheet.getWorkbook().createCellStyle();
    cellStyle.setAlignment(CellStyle.ALIGN_LEFT);
    cellStyle.setVerticalAlignment(CellStyle.VERTICAL_TOP);
    cellStyle.setWrapText(true);/*  ww w .ja  v  a 2 s.  com*/
    Font font = sheet.getWorkbook().createFont();
    font.setBoldweight(Font.BOLDWEIGHT_BOLD);
    font.setFontHeightInPoints(METADATA_NAME_FONT_SIZE);
    font.setFontName(FONT_NAME);
    cellStyle.setFont(font);
    return cellStyle;
}

From source file:it.eng.spagobi.engines.worksheet.exporter.WorkSheetXLSExporter.java

License:Mozilla Public License

public CellStyle buildMetadataValueCellStyle(Sheet sheet) {
    CellStyle cellStyle = sheet.getWorkbook().createCellStyle();
    cellStyle.setAlignment(CellStyle.ALIGN_LEFT);
    cellStyle.setVerticalAlignment(CellStyle.VERTICAL_TOP);
    cellStyle.setWrapText(true);/*w ww .  j  av  a2s.  co m*/
    Font font = sheet.getWorkbook().createFont();
    font.setFontHeightInPoints(METADATA_VALUE_FONT_SIZE);
    font.setFontName(FONT_NAME);
    cellStyle.setFont(font);
    return cellStyle;
}

From source file:it.eng.spagobi.engines.worksheet.exporter.WorkSheetXLSExporter.java

License:Mozilla Public License

public CellStyle buildFiltersTitleCellStyle(Sheet sheet) {
    CellStyle cellStyle = sheet.getWorkbook().createCellStyle();
    cellStyle.setAlignment(CellStyle.ALIGN_LEFT);
    cellStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    cellStyle.setWrapText(false);//from   ww  w  . j ava  2 s.  c o m
    Font font = sheet.getWorkbook().createFont();
    font.setBoldweight(Font.BOLDWEIGHT_BOLD);
    font.setFontHeightInPoints(FILTERS_TITLE_FONT_SIZE);
    font.setFontName(FONT_NAME);
    cellStyle.setFont(font);
    return cellStyle;
}

From source file:it.eng.spagobi.engines.worksheet.exporter.WorkSheetXLSExporter.java

License:Mozilla Public License

public CellStyle buildFiltersValuesCellStyle(Sheet sheet) {
    CellStyle cellStyle = sheet.getWorkbook().createCellStyle();
    cellStyle.setAlignment(CellStyle.ALIGN_LEFT);
    cellStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    cellStyle.setWrapText(false);/* www  .j a  v a 2s.  c  o m*/
    Font font = sheet.getWorkbook().createFont();
    font.setFontHeightInPoints(FILTERS_VALUES_FONT_SIZE);
    font.setFontName(FONT_NAME);
    cellStyle.setFont(font);
    return cellStyle;
}

From source file:javaapp.generateAnomolies.java

public static void generateAnomolyReport() throws IOException {

    XSSFWorkbook workbook = new XSSFWorkbook();

    HashMap<String, List<String>> hmd = new HashMap<String, List<String>>();
    HashMap<String, List<String>> hmc = new HashMap<String, List<String>>();
    HashMap<String, List<String>> uhmd = new HashMap<String, List<String>>();
    HashMap<String, List<String>> uhmc = new HashMap<String, List<String>>();

    hmd = getAnomolies("transrec", "Debtors", 0);
    hmc = getAnomolies("ctransrec", "Creditors", 1);
    uhmd = getAnomoliesUninv("uninv", "Uninv_Debtors", 2);
    uhmc = getAnomoliesUninv("cuninv", "Uninv_Creditors", 3);

    List ls;/*from  w w w.j av  a  2  s . c  o  m*/
    List ls2, ls3, ls4;

    Font font = workbook.createFont();
    font.setFontHeightInPoints((short) 12);
    font.setFontName("Cambria");

    Font hfont = workbook.createFont();
    hfont.setFontHeightInPoints((short) 12);
    hfont.setFontName("Cambria");

    CellStyle style = workbook.createCellStyle();
    CellStyle hstyle = workbook.createCellStyle();

    style.setFont(font);
    style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
    style.setFillPattern(CellStyle.SOLID_FOREGROUND);

    hstyle.setFont(font);
    hstyle.setFillForegroundColor(IndexedColors.DARK_BLUE.getIndex());
    hstyle.setFillPattern(CellStyle.SOLID_FOREGROUND);

    //System.out.println(hm);
    XSSFSheet sheet = workbook.createSheet("Debtors");
    XSSFSheet sheet2 = workbook.createSheet("Creditors");
    XSSFSheet sheet3 = workbook.createSheet("Uninv_Debtors");
    XSSFSheet sheet4 = workbook.createSheet("Uninv_Creditors");

    Iterator iterator = hmd.keySet().iterator();

    int rowCount = 0;
    Row row = sheet.createRow(0);
    Cell hcell = row.createCell(1);
    hcell.setCellValue((String) "RPPS");
    hcell.setCellStyle(hstyle);
    hcell = row.createCell(2);
    hcell.setCellValue((String) "SVC");
    hcell.setCellStyle(hstyle);
    hcell = row.createCell(3);
    hcell.setCellValue((String) "OPEN");
    hcell.setCellStyle(hstyle);
    hcell = row.createCell(4);
    hcell.setCellValue((String) "RINVOICE");
    hcell.setCellStyle(hstyle);
    hcell = row.createCell(5);
    hcell.setCellValue((String) "CORRECTION");
    hcell.setCellStyle(hstyle);
    hcell = row.createCell(6);
    hcell.setCellValue((String) "ADJUST");
    hcell.setCellStyle(hstyle);
    hcell = row.createCell(7);
    hcell.setCellValue((String) "O1C");
    hcell.setCellStyle(hstyle);
    hcell = row.createCell(8);
    hcell.setCellValue((String) "SETTLED");
    hcell.setCellStyle(hstyle);
    hcell = row.createCell(9);
    hcell.setCellValue((String) "ALLOC");
    hcell.setCellStyle(hstyle);
    hcell = row.createCell(10);
    hcell.setCellValue((String) "WRITEOFF");
    hcell.setCellStyle(hstyle);
    hcell = row.createCell(11);
    hcell.setCellValue((String) "CLOSE");
    hcell.setCellStyle(hstyle);
    hcell = row.createCell(12);
    hcell.setCellValue((String) "RECDIFF");
    hcell.setCellStyle(hstyle);

    while (iterator.hasNext()) {

        row = sheet.createRow(++rowCount);
        int columnCount = 0;
        String field = "";

        String key = iterator.next().toString();
        field = key;
        Cell cell = row.createCell(++columnCount);

        if (field instanceof String) {
            cell.setCellValue((String) field);
            cell.setCellStyle(style);
        }

        //System.out.println(hm.get(key));
        ls = (List<String>) hmd.get(key);
        System.out.println(ls);
        Iterator<String> ite = ls.iterator();
        while (ite.hasNext()) {
            field = ite.next();
            //System.out.println( ite.next() );
            cell = row.createCell(++columnCount);
            if (field instanceof String) {
                cell.setCellValue((String) field);
            }

            cell.setCellStyle(style);

        }

    }

    Iterator iterator2 = hmc.keySet().iterator();
    rowCount = 0;

    while (iterator2.hasNext()) {

        row = sheet2.createRow(++rowCount);
        int columnCount = 0;
        String field = "";

        String key = iterator2.next().toString();
        field = key;
        Cell cell = row.createCell(++columnCount);
        if (field instanceof String) {
            cell.setCellValue((String) field);
            cell.setCellStyle(style);
        }

        //System.out.println(hm.get(key));
        ls2 = (List<String>) hmc.get(key);
        System.out.println(ls2);
        Iterator<String> ite = ls2.iterator();
        while (ite.hasNext()) {
            field = ite.next();
            //System.out.println( ite.next() );
            cell = row.createCell(++columnCount);
            if (field instanceof String) {
                cell.setCellValue((String) field);
                cell.setCellStyle(style);
            }

        }

    }

    // uninv debtors

    Iterator iterator3 = uhmd.keySet().iterator();
    rowCount = 0;

    while (iterator3.hasNext()) {

        row = sheet3.createRow(++rowCount);
        int columnCount = 0;
        String field = "";

        String key = iterator3.next().toString();
        field = key;
        Cell cell = row.createCell(++columnCount);
        if (field instanceof String) {
            cell.setCellValue((String) field);
            cell.setCellStyle(style);
        }

        //System.out.println(hm.get(key));
        ls3 = (List<String>) hmc.get(key);
        System.out.println(ls3);
        Iterator<String> ite = ls3.iterator();
        while (ite.hasNext()) {
            field = ite.next();
            //System.out.println( ite.next() );
            cell = row.createCell(++columnCount);
            if (field instanceof String) {
                cell.setCellValue((String) field);
                cell.setCellStyle(style);
            }

        }

    }

    // uninv creditors

    Iterator iterator4 = uhmc.keySet().iterator();
    rowCount = 0;

    while (iterator4.hasNext()) {

        row = sheet4.createRow(++rowCount);
        int columnCount = 0;
        String field = "";

        String key = iterator4.next().toString();
        field = key;
        Cell cell = row.createCell(++columnCount);
        if (field instanceof String) {
            cell.setCellValue((String) field);
            cell.setCellStyle(style);
        }

        //System.out.println(hm.get(key));
        ls4 = (List<String>) uhmc.get(key);
        System.out.println(ls4);
        Iterator<String> ite = ls4.iterator();
        while (ite.hasNext()) {
            field = ite.next();
            //System.out.println( ite.next() );
            cell = row.createCell(++columnCount);
            if (field instanceof String) {
                cell.setCellValue((String) field);
                cell.setCellStyle(style);
            }

        }

    }
    /*
    Object[][] bookData = {
        {"Head First Java", "Kathy Serria", 79},
        {"Effective Java", "Joshua Bloch", 36},
        {"Clean Code", "Robert martin", 42},
        {"Thinking in Java", "Bruce Eckel", 35},
    };
            
            
            
            
            
     //int rowCount = 0;
    for (Object[] aBook : bookData) {
    Row row = sheet.createRow(++rowCount);
             
    int columnCount = 0;
             
    for (Object field : aBook) {
        Cell cell = row.createCell(++columnCount);
        if (field instanceof String) {
            cell.setCellValue((String) field);
        } else if (field instanceof Integer) {
            cell.setCellValue((Integer) field);
        }
    }
             
    }
            
    */
    // workbook.setSheetName(n, WorkbookUtil.createSafeSheetName("Debtors"));
    try (FileOutputStream outputStream = new FileOutputStream("anomolies/GBRCN_Anomolies_27April.xlsx")) {
        workbook.write(outputStream);
    }

}

From source file:jdbreport.model.io.xls.poi.Excel2003Writer.java

License:Apache License

private Font getFont(short fontIndex, AttributeSet attributeSet, Workbook wb) {
    Font font = null;
    String family = null;//from  w ww  . java 2  s .com
    String sizeStr = null;
    short color = 0;
    boolean bold = false;
    boolean italic = false;
    boolean underline = false;
    boolean line_through = false;
    boolean sub = false;
    boolean sup = false;
    Enumeration<?> en = attributeSet.getAttributeNames();
    while (en.hasMoreElements()) {
        Object key = en.nextElement();
        String name = key.toString();
        String attribute = attributeSet.getAttribute(key).toString();

        switch (name) {
        case "font-weight":
            bold = attribute.equals("bold");
            break;
        case "font-style":
            italic = attribute.equals("italic");
            break;
        case "text-decoration":
            if (attribute.equals("underline")) {
                underline = true;
            } else if (attribute.equals("line-through")) {
                line_through = true;
            }
            break;
        case "font-family":
            family = attribute;
            break;
        case "font-size":
            sizeStr = attribute;

            break;
        case "color":
            Color fontColor = Utils.colorByName(attribute);
            if (fontColor == null) {
                try {
                    fontColor = Utils.stringToColor(attribute);
                } catch (Exception ignored) {

                }
            }
            if (fontColor != null) {
                color = colorToIndex(wb, fontColor);
            }
            break;
        case "vertical-align":
            if (attribute.equals("sub")) {
                sub = true;
            } else if (attribute.equals("sup")) {
                sup = true;
            }
            break;
        }
    }
    if (family != null || bold || italic || underline || line_through || color > 0 || sizeStr != null || sub
            || sup) {

        font = wb.createFont();
        if (fontIndex > 0) {
            Font parentFont = wb.getFontAt(fontIndex);
            if (parentFont != null) {
                font.setBold(parentFont.getBold());
                font.setColor(parentFont.getColor());
                try {
                    font.setCharSet(parentFont.getCharSet());
                } catch (Throwable ignored) {
                }
                font.setFontHeight(parentFont.getFontHeight());
                font.setFontName(parentFont.getFontName());
                font.setItalic(parentFont.getItalic());
                font.setStrikeout(parentFont.getStrikeout());
                font.setUnderline(parentFont.getUnderline());
                font.setTypeOffset(parentFont.getTypeOffset());
            }
        }
        if (family != null) {
            font.setFontName(family);
        }
        if (bold) {
            font.setBold(true);
        }
        if (italic) {
            font.setItalic(italic);
        }
        if (underline) {
            font.setUnderline(Font.U_SINGLE);
        }
        if (line_through) {
            font.setStrikeout(line_through);
        }
        if (color > 0) {
            font.setColor(color);
        }
        if (sizeStr != null) {
            short size = (short) Float.parseFloat(sizeStr);
            if (sizeStr.charAt(0) == '+' || sizeStr.charAt(0) == '-') {
                size = (short) (Content.pointToSize(font.getFontHeightInPoints()) + size);
            }
            font.setFontHeightInPoints(Content.sizeToPoints(size));
        }
        if (sup) {
            font.setTypeOffset(Font.SS_SUPER);
        } else if (sub) {
            font.setTypeOffset(Font.SS_SUB);
        }
    }
    return font;
}

From source file:jdbreport.model.io.xls.poi.Excel2003Writer.java

License:Apache License

protected CellStyle createStyle(jdbreport.model.CellStyle style, Workbook wb) {

    CellStyle newStyle = wb.createCellStyle();
    newStyle.setAlignment(convertHorizontalAlign(style.getHorizontalAlignment()));
    newStyle.setVerticalAlignment(convertVerticalAlign(style.getVerticalAlignment()));

    Border border = style.getBorders(Border.LINE_BOTTOM);
    if (border != null) {
        newStyle.setBorderBottom(getBorder(border));
        newStyle.setBottomBorderColor(colorToIndex(wb, border.getColor()));
    }//  w  w  w .ja va 2 s  . c o  m
    border = style.getBorders(Border.LINE_TOP);
    if (border != null) {
        newStyle.setBorderTop(getBorder(border));
        newStyle.setTopBorderColor(colorToIndex(wb, border.getColor()));
    }
    border = style.getBorders(Border.LINE_LEFT);
    if (border != null) {
        newStyle.setBorderLeft(getBorder(border));
        newStyle.setLeftBorderColor(colorToIndex(wb, border.getColor()));
    }
    border = style.getBorders(Border.LINE_RIGHT);
    if (border != null) {
        newStyle.setBorderRight(getBorder(border));
        newStyle.setRightBorderColor(colorToIndex(wb, border.getColor()));
    }

    Font font = wb.createFont();
    font.setFontName(style.getFamily());
    if (style.isBold()) {
        font.setBold(true);
    }
    font.setItalic(style.isItalic());
    if (style.isUnderline()) {
        font.setUnderline(Font.U_SINGLE);
    }
    if (style.isStrikethrough()) {
        font.setStrikeout(true);
    }
    font.setFontHeightInPoints((short) style.getSize());
    if (style.getForegroundColor() != null && !style.getForegroundColor().equals(Color.black)) {
        font.setColor(colorToIndex(wb, style.getForegroundColor()));
    }

    newStyle.setFont(font);

    if (style.getBackground() != null && !style.getBackground().equals(Color.white)) {
        short colorIndex = colorToIndex(wb, style.getBackground());
        newStyle.setFillForegroundColor(colorIndex);
        newStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
    }

    if (style.getAngle() != 0) {
        int angle = style.getAngle();
        if (angle > 90 && angle <= 180) {
            angle = 90;
        } else if (angle > 180 && angle <= 270) {
            angle = -90;
        } else if (angle > 270) {
            angle = -(360 - angle);
        }
        newStyle.setRotation((short) angle);
    }

    newStyle.setWrapText(style.isWrapLine());

    return newStyle;
}

From source file:jdbreport.model.io.xls.poi.Excel2007Writer.java

License:Apache License

protected CellStyle createStyle(jdbreport.model.CellStyle style, Workbook wb) {

    XSSFCellStyle newStyle = (XSSFCellStyle) wb.createCellStyle();
    newStyle.setAlignment(convertHorizontalAlign(style.getHorizontalAlignment()));
    newStyle.setVerticalAlignment(convertVerticalAlign(style.getVerticalAlignment()));

    Border border = style.getBorders(Border.LINE_BOTTOM);
    if (border != null) {
        newStyle.setBorderBottom(getBorder(border));
        newStyle.setBottomBorderColor(new XSSFColor(border.getColor()));
    }//from  w ww .  j  a  v  a  2 s . c om
    border = style.getBorders(Border.LINE_TOP);
    if (border != null) {
        newStyle.setBorderTop(getBorder(border));
        newStyle.setTopBorderColor(new XSSFColor(border.getColor()));
    }
    border = style.getBorders(Border.LINE_LEFT);
    if (border != null) {
        newStyle.setBorderLeft(getBorder(border));
        newStyle.setLeftBorderColor(new XSSFColor(border.getColor()));
    }
    border = style.getBorders(Border.LINE_RIGHT);
    if (border != null) {
        newStyle.setBorderRight(getBorder(border));
        newStyle.setRightBorderColor(new XSSFColor(border.getColor()));
    }

    Font font = wb.createFont();
    font.setFontName(style.getFamily());
    if (style.isBold()) {
        font.setBold(true);
    }
    font.setItalic(style.isItalic());
    if (style.isUnderline()) {
        font.setUnderline(Font.U_SINGLE);
    }
    if (style.isStrikethrough()) {
        font.setStrikeout(true);
    }
    font.setFontHeightInPoints((short) style.getSize());
    if (style.getForegroundColor() != null && !style.getForegroundColor().equals(Color.black)) {
        font.setColor(colorToIndex(wb, style.getForegroundColor()));
    }

    newStyle.setFont(font);

    if (style.getBackground() != null && !style.getBackground().equals(Color.white)) {
        newStyle.setFillForegroundColor(new XSSFColor(style.getBackground()));
        newStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
    }

    if (style.getAngle() != 0) {
        int angle = style.getAngle();
        if (angle > 90 && angle <= 180) {
            angle = 90;
        } else if (angle > 180 && angle <= 270) {
            angle = -90;
        } else if (angle > 270) {
            angle = -(360 - angle);
        }
        newStyle.setRotation((short) angle);
    }

    newStyle.setWrapText(style.isWrapLine());

    return newStyle;
}

From source file:net.ceos.project.poi.annotated.core.CellStyleHandler.java

License:Apache License

/**
 * Apply the font to the cell style.//from  w  ww.  ja va 2s . c  om
 * 
 * @param wb
 *            the {@link Workbook} in use
 * @param cs
 *            the {@link CellStyle} in use
 * @param name
 *            the font name
 * @param size
 *            the font size
 * @param c
 *            the font color
 * @param b
 *            is bold format
 * @param i
 *            is italic format
 * @param u
 *            is underline format
 */
protected static void applyFont(final Workbook wb, final CellStyle cs, final String name, final short size,
        final short c, final boolean b, final boolean i, final byte u) {
    Font f = fontFactory.newInstance(wb);
    f.setFontName(name);
    f.setFontHeightInPoints(size);
    f.setColor(c);
    f.setBold(b);
    f.setItalic(i);
    f.setUnderline(u);
    cs.setFont(f);
}