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.

Excel cell inline text formatting set with GemBox.Spreadsheet for Java
Screenshot of 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.

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

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

        // 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

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

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

Want more?

Next example GitHub

Check the next example or select an example from the menu. You can also download our examples from the GitHub.

Like it?

Download Buy

If you want to try the GemBox.Spreadsheet for Java yourself, you can download the free version. It delivers the same performance and set of features as the professional version, but with some operations limited. To remove the limitation, you need to purchase a license.