Arbeta med teckensnitt i Apache POI och Aspose.Cells

Aspose.Cells - Arbeta med teckensnitt

Aspose.Cells tillhandahåller en klass,Arbetsboksom representerar en Microsoft Excel-fil. Klassen Workbook innehåller en WorksheetCollection som ger åtkomst till varje kalkylblad i en Excel-fil. Ett arbetsblad representeras avArbetsbladklass. Kalkylbladsklassen tillhandahåller en Cells-samling. Varje föremål i Cells-samlingen representerar ett objekt avCellklass.

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 - Arbeta med teckensnitt

Apache POI SS tillhandahåller teckensnittsklass för att ställa in olika teckensnittsinställningar.

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);

Ladda ner Running Code

Ladda ner provkod