Link to home
Start Free TrialLog in
Avatar of Christopher Schene
Christopher ScheneFlag for United States of America

asked on

Unable to instantiate Java Font class

When i attempt to create the Java font my my excel cell I get an error from Eclipse saying "Cannot instantiate the type Font"

Why can't I instantiate the class?

private  void createCell(Workbook wb, Row row, int i, short halign, short valign, int value) {
            CreationHelper ch = wb.getCreationHelper();
            DataFormat format = wb.createDataFormat();
            Cell cell = row.createCell(i);
            cell.setCellValue(value);
            CellStyle cellStyle = wb.createCellStyle();


            cellStyle.setDataFormat(format.getFormat("###0"));
            Font myFont = new Font("Courier", Font.COLOR_RED, 12);
            cellStyle.setFont(myFont);
            cellStyle.setFillBackgroundColor(IndexedColors.DARK_BLUE.getIndex());
            cellStyle.setFillForegroundColor(IndexedColors.WHITE.getIndex());
            //cellStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
            //cellStyle.setFillPattern(CellStyle.BORDER_THICK);


            cellStyle.setAlignment(halign);
            cellStyle.setVerticalAlignment(valign);

            cell.setCellStyle(cellStyle);

      }
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Make sure it's java.awt.Font and not something else
Avatar of Christopher Schene

ASKER

cellStyle.setFont(myFont); won't accept an object of type java.awt.Font: It wants  org.apache.poi.ss.usermodel.Font
SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I found that this works after much trial and error

      XSSFFont myFont= wb.createFont();
            myFont.setFontHeightInPoints((short)10);
            myFont.setFontName("Arial");
            myFont.setColor(IndexedColors.RED.getIndex());
            myFont.setBold(true);
            myFont.setItalic(false);
            cellStyle.setFont(myFont);
All right, so...? (Time to close this one I would think)
Sorry: completely spaced and forgot I left this open. :-(
Thanx 4 axxepting