Does anyone know how to change the color of the particular text of a cell in excel. I am using apache poi and I could find out to change the text color of entire cell. But I want only a particular text.
Eg: Cell A1 has Hello World I want "Hello" to be in blue and "World" to be in green. How do I do this?
The key is using the HSSFRichTextString object to set the value of the cell. This object has an applyFont method which accepts a startingIndex, endingIndex and a Font. Thus, you can create fonts having the colors you want, then apply them to parts of the cell value using applyFont().
Here is some example code I cobbled together (completely untested):
At first create a style
add then this line will be added in your code