Working with Fonts in Apache POI and Aspose.Cells
Contents
[
Hide
]
Aspose.Cells - Working with Fonts
Aspose.Cells provides a class, Workbook that represents a Microsoft Excel file. The Workbook class contains a WorksheetCollection that allows access to each worksheet in an Excel file. A worksheet is represented by the Worksheet class. Worksheet class provides a Cells collection. Each item in the Cells collection represents an object of the Cell class.
Java
//Adding some value to cell
Cell cell = cells.get("A1");
cell.setValue("This is Aspose test of fonts!");
//Setting the font name to "Courier New"
Style style = cell.getStyle();
Font font = style.getFont();
font.setName("Courier New");
font.setSize(24);
font.setBold(true);
font.setUnderline(FontUnderlineType.SINGLE);
font.setColor(Color.getBlue());
font.setStrikeout(true);
//font.setSubscript(true);
cell.setStyle(style);
Apache POI SS - HSSF XSSF - Working with Fonts
Apache POI SS provides Font class to set various Font settings.
Java
// Create a new font and alter it.
Font font = wb.createFont();
font.setFontHeightInPoints((short)24);
font.setFontName("Courier New");
font.setItalic(true);
font.setStrikeout(true);
// Fonts are set into a style so create a new one to use.
CellStyle style = wb.createCellStyle();
style.setFont(font);
// Create a cell and put a value in it.
Cell cell = row.createCell(1);
cell.setCellValue("This is a test of fonts");
cell.setCellStyle(style);
Download Running Code
Download Sample Code
For more details, visit Dealing with Font Settings.