Excel cell inline text formatting

Using GemBox.Spreadsheet for Java you can apply font formatting (size, color, font type, italic and strikeout properties, different levels of boldness, underlining, subscript and superscript) to individual characters and words.

Following example shows how to format individual characters and words within a cell.

Screenshot of Excel cell inline text formatting set with GemBox.Spreadsheet for Java
Excel cell inline text formatting set with GemBox.Spreadsheet for Java
import com.gembox.spreadsheet.*;

class Program {

    public static void main(String[] args) throws java.io.IOException {
        // If using Professional version, put your serial key below.
        SpreadsheetInfo.setLicense("FREE-LIMITED-KEY");

        ExcelFile workbook = new ExcelFile();
        ExcelWorksheet worksheet = workbook.addWorksheet("Inline Text Formatting");

        worksheet.getCell(0, 0).setValue("Inline text formatting examples:");
        worksheet.getPrintOptions().setPrintGridlines(true);

        // Column width of 20 characters.
        worksheet.getColumn(0).setWidth(20 * 256);

        worksheet.getCell(2, 0).setValue("This is big and red text!");

        // Apply size to 'big and red' part of text
        worksheet.getCell(2, 0).getCharacters(8, 11).getFont().setSize(400);

        // Apply color to 'red' part of text
        worksheet.getCell(2, 0).getCharacters(16, 3).getFont().setColor(SpreadsheetColor.fromName(ColorName.RED));

        // Format cell content
        worksheet.getCell(4, 0).setValue("Formatting selected characters with GemBox.Spreadsheet for Java component.");
        worksheet.getCell(4, 0).getStyle().getFont().setColor(SpreadsheetColor.fromName(ColorName.BLUE));
        worksheet.getCell(4, 0).getStyle().getFont().setItalic(true);
        worksheet.getCell(4, 0).getStyle().setWrapText(true);

        // Get characters from index 36 to the end of string
        FormattedCharacterRange characters = worksheet.getCell(4, 0).getCharacters(36);

        // Apply color and underline to selected characters
        characters.getFont().setColor(SpreadsheetColor.fromName(ColorName.ORANGE));
        characters.getFont().setUnderlineStyle(UnderlineStyle.SINGLE);

        // Write selected characters
        worksheet.getCell(6, 0).setValue("Selected characters: " + characters.getText());

        workbook.save("Inline Text Formatting.%OutputFileType%");
    }
}

Check next example or download examples from GitHub.