1.

How Will You Add A Font To A Cell Using Apache Poi?

Answer»

XSSFFONT CLASS is used to add a font to a cell. Following CODE snippet can be used to set the background color of a cell to "Green".

//Create a new font and alter it.

XSSFFont font = workbook.createFont();

font.setFontHeightInPoints((short) 30);

font.setFontName("IMPACT");

font.setItalic(TRUE);

font.setColor(HSSFColor.BRIGHT_GREEN.index);

//Set font into style

XSSFCellStyle style = workbook.createCellStyle();

style.setFont(font);

XSSFFont class is used to add a font to a cell. Following code snippet can be used to set the background color of a cell to "Green".

//Create a new font and alter it.

XSSFFont font = workbook.createFont();

font.setFontHeightInPoints((short) 30);

font.setFontName("IMPACT");

font.setItalic(true);

font.setColor(HSSFColor.BRIGHT_GREEN.index);

//Set font into style

XSSFCellStyle style = workbook.createCellStyle();

style.setFont(font);



Discussion

No Comment Found