Christopher Schene
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(fo rmat.getFo rmat("###0 "));
Font myFont = new Font("Courier", Font.COLOR_RED, 12);
cellStyle.setFont(myFont);
cellStyle.setFillBackgroun dColor(Ind exedColors .DARK_BLUE .getIndex( ));
cellStyle.setFillForegroun dColor(Ind exedColors .WHITE.get Index());
//cellStyle.setFillPattern (CellStyle .SOLID_FOR EGROUND);
//cellStyle.setFillPattern (CellStyle .BORDER_TH ICK);
cellStyle.setAlignment(hal ign);
cellStyle.setVerticalAlign ment(valig n);
cell.setCellStyle(cellStyl e);
}
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(fo
Font myFont = new Font("Courier", Font.COLOR_RED, 12);
cellStyle.setFont(myFont);
cellStyle.setFillBackgroun
cellStyle.setFillForegroun
//cellStyle.setFillPattern
//cellStyle.setFillPattern
cellStyle.setAlignment(hal
cellStyle.setVerticalAlign
cell.setCellStyle(cellStyl
}
Make sure it's java.awt.Font and not something else
ASKER
cellStyle.setFont(myFont); won't accept an object of type java.awt.Font: It wants org.apache.poi.ss.usermode l.Font
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I found that this works after much trial and error
XSSFFont myFont= wb.createFont();
myFont.setFontHeightInPoin ts((short) 10);
myFont.setFontName("Arial" );
myFont.setColor(IndexedCol ors.RED.ge tIndex());
myFont.setBold(true);
myFont.setItalic(false);
cellStyle.setFont(myFont);
XSSFFont myFont= wb.createFont();
myFont.setFontHeightInPoin
myFont.setFontName("Arial"
myFont.setColor(IndexedCol
myFont.setBold(true);
myFont.setItalic(false);
cellStyle.setFont(myFont);
All right, so...? (Time to close this one I would think)
ASKER
Sorry: completely spaced and forgot I left this open. :-(
Thanx 4 axxepting